@lolyjs/core 0.2.0-alpha.31 → 0.2.0-alpha.33

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/index.js CHANGED
@@ -9871,8 +9871,8 @@ var require_built3 = __commonJS({
9871
9871
  });
9872
9872
 
9873
9873
  // src/server.ts
9874
- import fs19 from "fs";
9875
- import path25 from "path";
9874
+ import fs20 from "fs";
9875
+ import path26 from "path";
9876
9876
 
9877
9877
  // modules/server/utils/server-dir.ts
9878
9878
  init_globals();
@@ -12515,7 +12515,7 @@ var ReaddirpStream = class extends Readable {
12515
12515
  this._directoryFilter = normalizeFilter(opts.directoryFilter);
12516
12516
  const statMethod = opts.lstat ? lstat : stat;
12517
12517
  if (wantBigintFsStats) {
12518
- this._stat = (path30) => statMethod(path30, { bigint: true });
12518
+ this._stat = (path31) => statMethod(path31, { bigint: true });
12519
12519
  } else {
12520
12520
  this._stat = statMethod;
12521
12521
  }
@@ -12540,8 +12540,8 @@ var ReaddirpStream = class extends Readable {
12540
12540
  const par = this.parent;
12541
12541
  const fil = par && par.files;
12542
12542
  if (fil && fil.length > 0) {
12543
- const { path: path30, depth } = par;
12544
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path30));
12543
+ const { path: path31, depth } = par;
12544
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path31));
12545
12545
  const awaited = await Promise.all(slice);
12546
12546
  for (const entry of awaited) {
12547
12547
  if (!entry)
@@ -12581,20 +12581,20 @@ var ReaddirpStream = class extends Readable {
12581
12581
  this.reading = false;
12582
12582
  }
12583
12583
  }
12584
- async _exploreDir(path30, depth) {
12584
+ async _exploreDir(path31, depth) {
12585
12585
  let files;
12586
12586
  try {
12587
- files = await readdir(path30, this._rdOptions);
12587
+ files = await readdir(path31, this._rdOptions);
12588
12588
  } catch (error) {
12589
12589
  this._onError(error);
12590
12590
  }
12591
- return { files, depth, path: path30 };
12591
+ return { files, depth, path: path31 };
12592
12592
  }
12593
- async _formatEntry(dirent, path30) {
12593
+ async _formatEntry(dirent, path31) {
12594
12594
  let entry;
12595
12595
  const basename3 = this._isDirent ? dirent.name : dirent;
12596
12596
  try {
12597
- const fullPath = presolve(pjoin(path30, basename3));
12597
+ const fullPath = presolve(pjoin(path31, basename3));
12598
12598
  entry = { path: prelative(this._root, fullPath), fullPath, basename: basename3 };
12599
12599
  entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
12600
12600
  } catch (err) {
@@ -12994,16 +12994,16 @@ var delFromSet = (main, prop, item) => {
12994
12994
  };
12995
12995
  var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
12996
12996
  var FsWatchInstances = /* @__PURE__ */ new Map();
12997
- function createFsWatchInstance(path30, options, listener, errHandler, emitRaw) {
12997
+ function createFsWatchInstance(path31, options, listener, errHandler, emitRaw) {
12998
12998
  const handleEvent = (rawEvent, evPath) => {
12999
- listener(path30);
13000
- emitRaw(rawEvent, evPath, { watchedPath: path30 });
13001
- if (evPath && path30 !== evPath) {
13002
- fsWatchBroadcast(sysPath.resolve(path30, evPath), KEY_LISTENERS, sysPath.join(path30, evPath));
12999
+ listener(path31);
13000
+ emitRaw(rawEvent, evPath, { watchedPath: path31 });
13001
+ if (evPath && path31 !== evPath) {
13002
+ fsWatchBroadcast(sysPath.resolve(path31, evPath), KEY_LISTENERS, sysPath.join(path31, evPath));
13003
13003
  }
13004
13004
  };
13005
13005
  try {
13006
- return fs_watch(path30, {
13006
+ return fs_watch(path31, {
13007
13007
  persistent: options.persistent
13008
13008
  }, handleEvent);
13009
13009
  } catch (error) {
@@ -13019,12 +13019,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
13019
13019
  listener(val1, val2, val3);
13020
13020
  });
13021
13021
  };
13022
- var setFsWatchListener = (path30, fullPath, options, handlers) => {
13022
+ var setFsWatchListener = (path31, fullPath, options, handlers) => {
13023
13023
  const { listener, errHandler, rawEmitter } = handlers;
13024
13024
  let cont = FsWatchInstances.get(fullPath);
13025
13025
  let watcher;
13026
13026
  if (!options.persistent) {
13027
- watcher = createFsWatchInstance(path30, options, listener, errHandler, rawEmitter);
13027
+ watcher = createFsWatchInstance(path31, options, listener, errHandler, rawEmitter);
13028
13028
  if (!watcher)
13029
13029
  return;
13030
13030
  return watcher.close.bind(watcher);
@@ -13035,7 +13035,7 @@ var setFsWatchListener = (path30, fullPath, options, handlers) => {
13035
13035
  addAndConvert(cont, KEY_RAW, rawEmitter);
13036
13036
  } else {
13037
13037
  watcher = createFsWatchInstance(
13038
- path30,
13038
+ path31,
13039
13039
  options,
13040
13040
  fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
13041
13041
  errHandler,
@@ -13050,7 +13050,7 @@ var setFsWatchListener = (path30, fullPath, options, handlers) => {
13050
13050
  cont.watcherUnusable = true;
13051
13051
  if (isWindows && error.code === "EPERM") {
13052
13052
  try {
13053
- const fd = await open(path30, "r");
13053
+ const fd = await open(path31, "r");
13054
13054
  await fd.close();
13055
13055
  broadcastErr(error);
13056
13056
  } catch (err) {
@@ -13081,7 +13081,7 @@ var setFsWatchListener = (path30, fullPath, options, handlers) => {
13081
13081
  };
13082
13082
  };
13083
13083
  var FsWatchFileInstances = /* @__PURE__ */ new Map();
13084
- var setFsWatchFileListener = (path30, fullPath, options, handlers) => {
13084
+ var setFsWatchFileListener = (path31, fullPath, options, handlers) => {
13085
13085
  const { listener, rawEmitter } = handlers;
13086
13086
  let cont = FsWatchFileInstances.get(fullPath);
13087
13087
  const copts = cont && cont.options;
@@ -13103,7 +13103,7 @@ var setFsWatchFileListener = (path30, fullPath, options, handlers) => {
13103
13103
  });
13104
13104
  const currmtime = curr.mtimeMs;
13105
13105
  if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
13106
- foreach(cont.listeners, (listener2) => listener2(path30, curr));
13106
+ foreach(cont.listeners, (listener2) => listener2(path31, curr));
13107
13107
  }
13108
13108
  })
13109
13109
  };
@@ -13131,13 +13131,13 @@ var NodeFsHandler = class {
13131
13131
  * @param listener on fs change
13132
13132
  * @returns closer for the watcher instance
13133
13133
  */
13134
- _watchWithNodeFs(path30, listener) {
13134
+ _watchWithNodeFs(path31, listener) {
13135
13135
  const opts = this.fsw.options;
13136
- const directory = sysPath.dirname(path30);
13137
- const basename3 = sysPath.basename(path30);
13136
+ const directory = sysPath.dirname(path31);
13137
+ const basename3 = sysPath.basename(path31);
13138
13138
  const parent = this.fsw._getWatchedDir(directory);
13139
13139
  parent.add(basename3);
13140
- const absolutePath = sysPath.resolve(path30);
13140
+ const absolutePath = sysPath.resolve(path31);
13141
13141
  const options = {
13142
13142
  persistent: opts.persistent
13143
13143
  };
@@ -13147,12 +13147,12 @@ var NodeFsHandler = class {
13147
13147
  if (opts.usePolling) {
13148
13148
  const enableBin = opts.interval !== opts.binaryInterval;
13149
13149
  options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
13150
- closer = setFsWatchFileListener(path30, absolutePath, options, {
13150
+ closer = setFsWatchFileListener(path31, absolutePath, options, {
13151
13151
  listener,
13152
13152
  rawEmitter: this.fsw._emitRaw
13153
13153
  });
13154
13154
  } else {
13155
- closer = setFsWatchListener(path30, absolutePath, options, {
13155
+ closer = setFsWatchListener(path31, absolutePath, options, {
13156
13156
  listener,
13157
13157
  errHandler: this._boundHandleError,
13158
13158
  rawEmitter: this.fsw._emitRaw
@@ -13174,7 +13174,7 @@ var NodeFsHandler = class {
13174
13174
  let prevStats = stats;
13175
13175
  if (parent.has(basename3))
13176
13176
  return;
13177
- const listener = async (path30, newStats) => {
13177
+ const listener = async (path31, newStats) => {
13178
13178
  if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
13179
13179
  return;
13180
13180
  if (!newStats || newStats.mtimeMs === 0) {
@@ -13188,11 +13188,11 @@ var NodeFsHandler = class {
13188
13188
  this.fsw._emit(EV.CHANGE, file, newStats2);
13189
13189
  }
13190
13190
  if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
13191
- this.fsw._closeFile(path30);
13191
+ this.fsw._closeFile(path31);
13192
13192
  prevStats = newStats2;
13193
13193
  const closer2 = this._watchWithNodeFs(file, listener);
13194
13194
  if (closer2)
13195
- this.fsw._addPathCloser(path30, closer2);
13195
+ this.fsw._addPathCloser(path31, closer2);
13196
13196
  } else {
13197
13197
  prevStats = newStats2;
13198
13198
  }
@@ -13224,7 +13224,7 @@ var NodeFsHandler = class {
13224
13224
  * @param item basename of this item
13225
13225
  * @returns true if no more processing is needed for this entry.
13226
13226
  */
13227
- async _handleSymlink(entry, directory, path30, item) {
13227
+ async _handleSymlink(entry, directory, path31, item) {
13228
13228
  if (this.fsw.closed) {
13229
13229
  return;
13230
13230
  }
@@ -13234,7 +13234,7 @@ var NodeFsHandler = class {
13234
13234
  this.fsw._incrReadyCount();
13235
13235
  let linkPath;
13236
13236
  try {
13237
- linkPath = await fsrealpath(path30);
13237
+ linkPath = await fsrealpath(path31);
13238
13238
  } catch (e) {
13239
13239
  this.fsw._emitReady();
13240
13240
  return true;
@@ -13244,12 +13244,12 @@ var NodeFsHandler = class {
13244
13244
  if (dir.has(item)) {
13245
13245
  if (this.fsw._symlinkPaths.get(full) !== linkPath) {
13246
13246
  this.fsw._symlinkPaths.set(full, linkPath);
13247
- this.fsw._emit(EV.CHANGE, path30, entry.stats);
13247
+ this.fsw._emit(EV.CHANGE, path31, entry.stats);
13248
13248
  }
13249
13249
  } else {
13250
13250
  dir.add(item);
13251
13251
  this.fsw._symlinkPaths.set(full, linkPath);
13252
- this.fsw._emit(EV.ADD, path30, entry.stats);
13252
+ this.fsw._emit(EV.ADD, path31, entry.stats);
13253
13253
  }
13254
13254
  this.fsw._emitReady();
13255
13255
  return true;
@@ -13278,9 +13278,9 @@ var NodeFsHandler = class {
13278
13278
  return;
13279
13279
  }
13280
13280
  const item = entry.path;
13281
- let path30 = sysPath.join(directory, item);
13281
+ let path31 = sysPath.join(directory, item);
13282
13282
  current.add(item);
13283
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path30, item)) {
13283
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path31, item)) {
13284
13284
  return;
13285
13285
  }
13286
13286
  if (this.fsw.closed) {
@@ -13289,8 +13289,8 @@ var NodeFsHandler = class {
13289
13289
  }
13290
13290
  if (item === target || !target && !previous.has(item)) {
13291
13291
  this.fsw._incrReadyCount();
13292
- path30 = sysPath.join(dir, sysPath.relative(dir, path30));
13293
- this._addToNodeFs(path30, initialAdd, wh, depth + 1);
13292
+ path31 = sysPath.join(dir, sysPath.relative(dir, path31));
13293
+ this._addToNodeFs(path31, initialAdd, wh, depth + 1);
13294
13294
  }
13295
13295
  }).on(EV.ERROR, this._boundHandleError);
13296
13296
  return new Promise((resolve3, reject) => {
@@ -13359,13 +13359,13 @@ var NodeFsHandler = class {
13359
13359
  * @param depth Child path actually targeted for watch
13360
13360
  * @param target Child path actually targeted for watch
13361
13361
  */
13362
- async _addToNodeFs(path30, initialAdd, priorWh, depth, target) {
13362
+ async _addToNodeFs(path31, initialAdd, priorWh, depth, target) {
13363
13363
  const ready = this.fsw._emitReady;
13364
- if (this.fsw._isIgnored(path30) || this.fsw.closed) {
13364
+ if (this.fsw._isIgnored(path31) || this.fsw.closed) {
13365
13365
  ready();
13366
13366
  return false;
13367
13367
  }
13368
- const wh = this.fsw._getWatchHelpers(path30);
13368
+ const wh = this.fsw._getWatchHelpers(path31);
13369
13369
  if (priorWh) {
13370
13370
  wh.filterPath = (entry) => priorWh.filterPath(entry);
13371
13371
  wh.filterDir = (entry) => priorWh.filterDir(entry);
@@ -13381,8 +13381,8 @@ var NodeFsHandler = class {
13381
13381
  const follow = this.fsw.options.followSymlinks;
13382
13382
  let closer;
13383
13383
  if (stats.isDirectory()) {
13384
- const absPath = sysPath.resolve(path30);
13385
- const targetPath = follow ? await fsrealpath(path30) : path30;
13384
+ const absPath = sysPath.resolve(path31);
13385
+ const targetPath = follow ? await fsrealpath(path31) : path31;
13386
13386
  if (this.fsw.closed)
13387
13387
  return;
13388
13388
  closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
@@ -13392,29 +13392,29 @@ var NodeFsHandler = class {
13392
13392
  this.fsw._symlinkPaths.set(absPath, targetPath);
13393
13393
  }
13394
13394
  } else if (stats.isSymbolicLink()) {
13395
- const targetPath = follow ? await fsrealpath(path30) : path30;
13395
+ const targetPath = follow ? await fsrealpath(path31) : path31;
13396
13396
  if (this.fsw.closed)
13397
13397
  return;
13398
13398
  const parent = sysPath.dirname(wh.watchPath);
13399
13399
  this.fsw._getWatchedDir(parent).add(wh.watchPath);
13400
13400
  this.fsw._emit(EV.ADD, wh.watchPath, stats);
13401
- closer = await this._handleDir(parent, stats, initialAdd, depth, path30, wh, targetPath);
13401
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path31, wh, targetPath);
13402
13402
  if (this.fsw.closed)
13403
13403
  return;
13404
13404
  if (targetPath !== void 0) {
13405
- this.fsw._symlinkPaths.set(sysPath.resolve(path30), targetPath);
13405
+ this.fsw._symlinkPaths.set(sysPath.resolve(path31), targetPath);
13406
13406
  }
13407
13407
  } else {
13408
13408
  closer = this._handleFile(wh.watchPath, stats, initialAdd);
13409
13409
  }
13410
13410
  ready();
13411
13411
  if (closer)
13412
- this.fsw._addPathCloser(path30, closer);
13412
+ this.fsw._addPathCloser(path31, closer);
13413
13413
  return false;
13414
13414
  } catch (error) {
13415
13415
  if (this.fsw._handleError(error)) {
13416
13416
  ready();
13417
- return path30;
13417
+ return path31;
13418
13418
  }
13419
13419
  }
13420
13420
  }
@@ -13457,26 +13457,26 @@ function createPattern(matcher) {
13457
13457
  }
13458
13458
  return () => false;
13459
13459
  }
13460
- function normalizePath(path30) {
13461
- if (typeof path30 !== "string")
13460
+ function normalizePath(path31) {
13461
+ if (typeof path31 !== "string")
13462
13462
  throw new Error("string expected");
13463
- path30 = sysPath2.normalize(path30);
13464
- path30 = path30.replace(/\\/g, "/");
13463
+ path31 = sysPath2.normalize(path31);
13464
+ path31 = path31.replace(/\\/g, "/");
13465
13465
  let prepend = false;
13466
- if (path30.startsWith("//"))
13466
+ if (path31.startsWith("//"))
13467
13467
  prepend = true;
13468
13468
  const DOUBLE_SLASH_RE2 = /\/\//;
13469
- while (path30.match(DOUBLE_SLASH_RE2))
13470
- path30 = path30.replace(DOUBLE_SLASH_RE2, "/");
13469
+ while (path31.match(DOUBLE_SLASH_RE2))
13470
+ path31 = path31.replace(DOUBLE_SLASH_RE2, "/");
13471
13471
  if (prepend)
13472
- path30 = "/" + path30;
13473
- return path30;
13472
+ path31 = "/" + path31;
13473
+ return path31;
13474
13474
  }
13475
13475
  function matchPatterns(patterns, testString, stats) {
13476
- const path30 = normalizePath(testString);
13476
+ const path31 = normalizePath(testString);
13477
13477
  for (let index = 0; index < patterns.length; index++) {
13478
13478
  const pattern = patterns[index];
13479
- if (pattern(path30, stats)) {
13479
+ if (pattern(path31, stats)) {
13480
13480
  return true;
13481
13481
  }
13482
13482
  }
@@ -13516,19 +13516,19 @@ var toUnix = (string) => {
13516
13516
  }
13517
13517
  return str;
13518
13518
  };
13519
- var normalizePathToUnix = (path30) => toUnix(sysPath2.normalize(toUnix(path30)));
13520
- var normalizeIgnored = (cwd = "") => (path30) => {
13521
- if (typeof path30 === "string") {
13522
- return normalizePathToUnix(sysPath2.isAbsolute(path30) ? path30 : sysPath2.join(cwd, path30));
13519
+ var normalizePathToUnix = (path31) => toUnix(sysPath2.normalize(toUnix(path31)));
13520
+ var normalizeIgnored = (cwd = "") => (path31) => {
13521
+ if (typeof path31 === "string") {
13522
+ return normalizePathToUnix(sysPath2.isAbsolute(path31) ? path31 : sysPath2.join(cwd, path31));
13523
13523
  } else {
13524
- return path30;
13524
+ return path31;
13525
13525
  }
13526
13526
  };
13527
- var getAbsolutePath = (path30, cwd) => {
13528
- if (sysPath2.isAbsolute(path30)) {
13529
- return path30;
13527
+ var getAbsolutePath = (path31, cwd) => {
13528
+ if (sysPath2.isAbsolute(path31)) {
13529
+ return path31;
13530
13530
  }
13531
- return sysPath2.join(cwd, path30);
13531
+ return sysPath2.join(cwd, path31);
13532
13532
  };
13533
13533
  var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
13534
13534
  var DirEntry = class {
@@ -13583,10 +13583,10 @@ var DirEntry = class {
13583
13583
  var STAT_METHOD_F = "stat";
13584
13584
  var STAT_METHOD_L = "lstat";
13585
13585
  var WatchHelper = class {
13586
- constructor(path30, follow, fsw) {
13586
+ constructor(path31, follow, fsw) {
13587
13587
  this.fsw = fsw;
13588
- const watchPath = path30;
13589
- this.path = path30 = path30.replace(REPLACER_RE, "");
13588
+ const watchPath = path31;
13589
+ this.path = path31 = path31.replace(REPLACER_RE, "");
13590
13590
  this.watchPath = watchPath;
13591
13591
  this.fullWatchPath = sysPath2.resolve(watchPath);
13592
13592
  this.dirParts = [];
@@ -13708,20 +13708,20 @@ var FSWatcher = class extends EventEmitter {
13708
13708
  this._closePromise = void 0;
13709
13709
  let paths = unifyPaths(paths_);
13710
13710
  if (cwd) {
13711
- paths = paths.map((path30) => {
13712
- const absPath = getAbsolutePath(path30, cwd);
13711
+ paths = paths.map((path31) => {
13712
+ const absPath = getAbsolutePath(path31, cwd);
13713
13713
  return absPath;
13714
13714
  });
13715
13715
  }
13716
- paths.forEach((path30) => {
13717
- this._removeIgnoredPath(path30);
13716
+ paths.forEach((path31) => {
13717
+ this._removeIgnoredPath(path31);
13718
13718
  });
13719
13719
  this._userIgnored = void 0;
13720
13720
  if (!this._readyCount)
13721
13721
  this._readyCount = 0;
13722
13722
  this._readyCount += paths.length;
13723
- Promise.all(paths.map(async (path30) => {
13724
- const res = await this._nodeFsHandler._addToNodeFs(path30, !_internal, void 0, 0, _origAdd);
13723
+ Promise.all(paths.map(async (path31) => {
13724
+ const res = await this._nodeFsHandler._addToNodeFs(path31, !_internal, void 0, 0, _origAdd);
13725
13725
  if (res)
13726
13726
  this._emitReady();
13727
13727
  return res;
@@ -13743,17 +13743,17 @@ var FSWatcher = class extends EventEmitter {
13743
13743
  return this;
13744
13744
  const paths = unifyPaths(paths_);
13745
13745
  const { cwd } = this.options;
13746
- paths.forEach((path30) => {
13747
- if (!sysPath2.isAbsolute(path30) && !this._closers.has(path30)) {
13746
+ paths.forEach((path31) => {
13747
+ if (!sysPath2.isAbsolute(path31) && !this._closers.has(path31)) {
13748
13748
  if (cwd)
13749
- path30 = sysPath2.join(cwd, path30);
13750
- path30 = sysPath2.resolve(path30);
13749
+ path31 = sysPath2.join(cwd, path31);
13750
+ path31 = sysPath2.resolve(path31);
13751
13751
  }
13752
- this._closePath(path30);
13753
- this._addIgnoredPath(path30);
13754
- if (this._watched.has(path30)) {
13752
+ this._closePath(path31);
13753
+ this._addIgnoredPath(path31);
13754
+ if (this._watched.has(path31)) {
13755
13755
  this._addIgnoredPath({
13756
- path: path30,
13756
+ path: path31,
13757
13757
  recursive: true
13758
13758
  });
13759
13759
  }
@@ -13817,38 +13817,38 @@ var FSWatcher = class extends EventEmitter {
13817
13817
  * @param stats arguments to be passed with event
13818
13818
  * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
13819
13819
  */
13820
- async _emit(event, path30, stats) {
13820
+ async _emit(event, path31, stats) {
13821
13821
  if (this.closed)
13822
13822
  return;
13823
13823
  const opts = this.options;
13824
13824
  if (isWindows)
13825
- path30 = sysPath2.normalize(path30);
13825
+ path31 = sysPath2.normalize(path31);
13826
13826
  if (opts.cwd)
13827
- path30 = sysPath2.relative(opts.cwd, path30);
13828
- const args = [path30];
13827
+ path31 = sysPath2.relative(opts.cwd, path31);
13828
+ const args = [path31];
13829
13829
  if (stats != null)
13830
13830
  args.push(stats);
13831
13831
  const awf = opts.awaitWriteFinish;
13832
13832
  let pw;
13833
- if (awf && (pw = this._pendingWrites.get(path30))) {
13833
+ if (awf && (pw = this._pendingWrites.get(path31))) {
13834
13834
  pw.lastChange = /* @__PURE__ */ new Date();
13835
13835
  return this;
13836
13836
  }
13837
13837
  if (opts.atomic) {
13838
13838
  if (event === EVENTS.UNLINK) {
13839
- this._pendingUnlinks.set(path30, [event, ...args]);
13839
+ this._pendingUnlinks.set(path31, [event, ...args]);
13840
13840
  setTimeout(() => {
13841
- this._pendingUnlinks.forEach((entry, path31) => {
13841
+ this._pendingUnlinks.forEach((entry, path32) => {
13842
13842
  this.emit(...entry);
13843
13843
  this.emit(EVENTS.ALL, ...entry);
13844
- this._pendingUnlinks.delete(path31);
13844
+ this._pendingUnlinks.delete(path32);
13845
13845
  });
13846
13846
  }, typeof opts.atomic === "number" ? opts.atomic : 100);
13847
13847
  return this;
13848
13848
  }
13849
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path30)) {
13849
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path31)) {
13850
13850
  event = EVENTS.CHANGE;
13851
- this._pendingUnlinks.delete(path30);
13851
+ this._pendingUnlinks.delete(path31);
13852
13852
  }
13853
13853
  }
13854
13854
  if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
@@ -13866,16 +13866,16 @@ var FSWatcher = class extends EventEmitter {
13866
13866
  this.emitWithAll(event, args);
13867
13867
  }
13868
13868
  };
13869
- this._awaitWriteFinish(path30, awf.stabilityThreshold, event, awfEmit);
13869
+ this._awaitWriteFinish(path31, awf.stabilityThreshold, event, awfEmit);
13870
13870
  return this;
13871
13871
  }
13872
13872
  if (event === EVENTS.CHANGE) {
13873
- const isThrottled = !this._throttle(EVENTS.CHANGE, path30, 50);
13873
+ const isThrottled = !this._throttle(EVENTS.CHANGE, path31, 50);
13874
13874
  if (isThrottled)
13875
13875
  return this;
13876
13876
  }
13877
13877
  if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
13878
- const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path30) : path30;
13878
+ const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path31) : path31;
13879
13879
  let stats2;
13880
13880
  try {
13881
13881
  stats2 = await stat3(fullPath);
@@ -13906,23 +13906,23 @@ var FSWatcher = class extends EventEmitter {
13906
13906
  * @param timeout duration of time to suppress duplicate actions
13907
13907
  * @returns tracking object or false if action should be suppressed
13908
13908
  */
13909
- _throttle(actionType, path30, timeout) {
13909
+ _throttle(actionType, path31, timeout) {
13910
13910
  if (!this._throttled.has(actionType)) {
13911
13911
  this._throttled.set(actionType, /* @__PURE__ */ new Map());
13912
13912
  }
13913
13913
  const action = this._throttled.get(actionType);
13914
13914
  if (!action)
13915
13915
  throw new Error("invalid throttle");
13916
- const actionPath = action.get(path30);
13916
+ const actionPath = action.get(path31);
13917
13917
  if (actionPath) {
13918
13918
  actionPath.count++;
13919
13919
  return false;
13920
13920
  }
13921
13921
  let timeoutObject;
13922
13922
  const clear = () => {
13923
- const item = action.get(path30);
13923
+ const item = action.get(path31);
13924
13924
  const count = item ? item.count : 0;
13925
- action.delete(path30);
13925
+ action.delete(path31);
13926
13926
  clearTimeout(timeoutObject);
13927
13927
  if (item)
13928
13928
  clearTimeout(item.timeoutObject);
@@ -13930,7 +13930,7 @@ var FSWatcher = class extends EventEmitter {
13930
13930
  };
13931
13931
  timeoutObject = setTimeout(clear, timeout);
13932
13932
  const thr = { timeoutObject, clear, count: 0 };
13933
- action.set(path30, thr);
13933
+ action.set(path31, thr);
13934
13934
  return thr;
13935
13935
  }
13936
13936
  _incrReadyCount() {
@@ -13944,44 +13944,44 @@ var FSWatcher = class extends EventEmitter {
13944
13944
  * @param event
13945
13945
  * @param awfEmit Callback to be called when ready for event to be emitted.
13946
13946
  */
13947
- _awaitWriteFinish(path30, threshold, event, awfEmit) {
13947
+ _awaitWriteFinish(path31, threshold, event, awfEmit) {
13948
13948
  const awf = this.options.awaitWriteFinish;
13949
13949
  if (typeof awf !== "object")
13950
13950
  return;
13951
13951
  const pollInterval = awf.pollInterval;
13952
13952
  let timeoutHandler;
13953
- let fullPath = path30;
13954
- if (this.options.cwd && !sysPath2.isAbsolute(path30)) {
13955
- fullPath = sysPath2.join(this.options.cwd, path30);
13953
+ let fullPath = path31;
13954
+ if (this.options.cwd && !sysPath2.isAbsolute(path31)) {
13955
+ fullPath = sysPath2.join(this.options.cwd, path31);
13956
13956
  }
13957
13957
  const now = /* @__PURE__ */ new Date();
13958
13958
  const writes = this._pendingWrites;
13959
13959
  function awaitWriteFinishFn(prevStat) {
13960
13960
  statcb(fullPath, (err, curStat) => {
13961
- if (err || !writes.has(path30)) {
13961
+ if (err || !writes.has(path31)) {
13962
13962
  if (err && err.code !== "ENOENT")
13963
13963
  awfEmit(err);
13964
13964
  return;
13965
13965
  }
13966
13966
  const now2 = Number(/* @__PURE__ */ new Date());
13967
13967
  if (prevStat && curStat.size !== prevStat.size) {
13968
- writes.get(path30).lastChange = now2;
13968
+ writes.get(path31).lastChange = now2;
13969
13969
  }
13970
- const pw = writes.get(path30);
13970
+ const pw = writes.get(path31);
13971
13971
  const df = now2 - pw.lastChange;
13972
13972
  if (df >= threshold) {
13973
- writes.delete(path30);
13973
+ writes.delete(path31);
13974
13974
  awfEmit(void 0, curStat);
13975
13975
  } else {
13976
13976
  timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
13977
13977
  }
13978
13978
  });
13979
13979
  }
13980
- if (!writes.has(path30)) {
13981
- writes.set(path30, {
13980
+ if (!writes.has(path31)) {
13981
+ writes.set(path31, {
13982
13982
  lastChange: now,
13983
13983
  cancelWait: () => {
13984
- writes.delete(path30);
13984
+ writes.delete(path31);
13985
13985
  clearTimeout(timeoutHandler);
13986
13986
  return event;
13987
13987
  }
@@ -13992,8 +13992,8 @@ var FSWatcher = class extends EventEmitter {
13992
13992
  /**
13993
13993
  * Determines whether user has asked to ignore this path.
13994
13994
  */
13995
- _isIgnored(path30, stats) {
13996
- if (this.options.atomic && DOT_RE.test(path30))
13995
+ _isIgnored(path31, stats) {
13996
+ if (this.options.atomic && DOT_RE.test(path31))
13997
13997
  return true;
13998
13998
  if (!this._userIgnored) {
13999
13999
  const { cwd } = this.options;
@@ -14003,17 +14003,17 @@ var FSWatcher = class extends EventEmitter {
14003
14003
  const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
14004
14004
  this._userIgnored = anymatch(list, void 0);
14005
14005
  }
14006
- return this._userIgnored(path30, stats);
14006
+ return this._userIgnored(path31, stats);
14007
14007
  }
14008
- _isntIgnored(path30, stat4) {
14009
- return !this._isIgnored(path30, stat4);
14008
+ _isntIgnored(path31, stat4) {
14009
+ return !this._isIgnored(path31, stat4);
14010
14010
  }
14011
14011
  /**
14012
14012
  * Provides a set of common helpers and properties relating to symlink handling.
14013
14013
  * @param path file or directory pattern being watched
14014
14014
  */
14015
- _getWatchHelpers(path30) {
14016
- return new WatchHelper(path30, this.options.followSymlinks, this);
14015
+ _getWatchHelpers(path31) {
14016
+ return new WatchHelper(path31, this.options.followSymlinks, this);
14017
14017
  }
14018
14018
  // Directory helpers
14019
14019
  // -----------------
@@ -14045,63 +14045,63 @@ var FSWatcher = class extends EventEmitter {
14045
14045
  * @param item base path of item/directory
14046
14046
  */
14047
14047
  _remove(directory, item, isDirectory) {
14048
- const path30 = sysPath2.join(directory, item);
14049
- const fullPath = sysPath2.resolve(path30);
14050
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path30) || this._watched.has(fullPath);
14051
- if (!this._throttle("remove", path30, 100))
14048
+ const path31 = sysPath2.join(directory, item);
14049
+ const fullPath = sysPath2.resolve(path31);
14050
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path31) || this._watched.has(fullPath);
14051
+ if (!this._throttle("remove", path31, 100))
14052
14052
  return;
14053
14053
  if (!isDirectory && this._watched.size === 1) {
14054
14054
  this.add(directory, item, true);
14055
14055
  }
14056
- const wp = this._getWatchedDir(path30);
14056
+ const wp = this._getWatchedDir(path31);
14057
14057
  const nestedDirectoryChildren = wp.getChildren();
14058
- nestedDirectoryChildren.forEach((nested) => this._remove(path30, nested));
14058
+ nestedDirectoryChildren.forEach((nested) => this._remove(path31, nested));
14059
14059
  const parent = this._getWatchedDir(directory);
14060
14060
  const wasTracked = parent.has(item);
14061
14061
  parent.remove(item);
14062
14062
  if (this._symlinkPaths.has(fullPath)) {
14063
14063
  this._symlinkPaths.delete(fullPath);
14064
14064
  }
14065
- let relPath = path30;
14065
+ let relPath = path31;
14066
14066
  if (this.options.cwd)
14067
- relPath = sysPath2.relative(this.options.cwd, path30);
14067
+ relPath = sysPath2.relative(this.options.cwd, path31);
14068
14068
  if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
14069
14069
  const event = this._pendingWrites.get(relPath).cancelWait();
14070
14070
  if (event === EVENTS.ADD)
14071
14071
  return;
14072
14072
  }
14073
- this._watched.delete(path30);
14073
+ this._watched.delete(path31);
14074
14074
  this._watched.delete(fullPath);
14075
14075
  const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
14076
- if (wasTracked && !this._isIgnored(path30))
14077
- this._emit(eventName, path30);
14078
- this._closePath(path30);
14076
+ if (wasTracked && !this._isIgnored(path31))
14077
+ this._emit(eventName, path31);
14078
+ this._closePath(path31);
14079
14079
  }
14080
14080
  /**
14081
14081
  * Closes all watchers for a path
14082
14082
  */
14083
- _closePath(path30) {
14084
- this._closeFile(path30);
14085
- const dir = sysPath2.dirname(path30);
14086
- this._getWatchedDir(dir).remove(sysPath2.basename(path30));
14083
+ _closePath(path31) {
14084
+ this._closeFile(path31);
14085
+ const dir = sysPath2.dirname(path31);
14086
+ this._getWatchedDir(dir).remove(sysPath2.basename(path31));
14087
14087
  }
14088
14088
  /**
14089
14089
  * Closes only file-specific watchers
14090
14090
  */
14091
- _closeFile(path30) {
14092
- const closers = this._closers.get(path30);
14091
+ _closeFile(path31) {
14092
+ const closers = this._closers.get(path31);
14093
14093
  if (!closers)
14094
14094
  return;
14095
14095
  closers.forEach((closer) => closer());
14096
- this._closers.delete(path30);
14096
+ this._closers.delete(path31);
14097
14097
  }
14098
- _addPathCloser(path30, closer) {
14098
+ _addPathCloser(path31, closer) {
14099
14099
  if (!closer)
14100
14100
  return;
14101
- let list = this._closers.get(path30);
14101
+ let list = this._closers.get(path31);
14102
14102
  if (!list) {
14103
14103
  list = [];
14104
- this._closers.set(path30, list);
14104
+ this._closers.set(path31, list);
14105
14105
  }
14106
14106
  list.push(closer);
14107
14107
  }
@@ -14787,12 +14787,12 @@ var DEFAULT_IGNORED_PATHS = [
14787
14787
  /^\/sockjs-node/
14788
14788
  // Hot reload websocket
14789
14789
  ];
14790
- function shouldIgnorePath(path30, ignoredPaths) {
14790
+ function shouldIgnorePath(path31, ignoredPaths) {
14791
14791
  return ignoredPaths.some((pattern) => {
14792
14792
  if (typeof pattern === "string") {
14793
- return path30 === pattern || path30.startsWith(pattern);
14793
+ return path31 === pattern || path31.startsWith(pattern);
14794
14794
  }
14795
- return pattern.test(path30);
14795
+ return pattern.test(path31);
14796
14796
  });
14797
14797
  }
14798
14798
  function requestLoggerMiddleware(options = {}) {
@@ -14951,11 +14951,11 @@ function createStrictRateLimiterFromConfig(config) {
14951
14951
  }
14952
14952
 
14953
14953
  // modules/server/middleware/auto-rate-limit.ts
14954
- function matchesStrictPattern(path30, patterns) {
14954
+ function matchesStrictPattern(path31, patterns) {
14955
14955
  for (const pattern of patterns) {
14956
14956
  const regexPattern = pattern.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\//g, "\\/");
14957
14957
  const regex = new RegExp(`^${regexPattern}$`);
14958
- if (regex.test(path30)) {
14958
+ if (regex.test(path31)) {
14959
14959
  return true;
14960
14960
  }
14961
14961
  }
@@ -15654,25 +15654,89 @@ function handleNotFound(res, urlPath) {
15654
15654
  }
15655
15655
  }
15656
15656
 
15657
- // modules/server/handlers/ssg.ts
15658
- import fs18 from "fs";
15657
+ // modules/server/global-middleware.ts
15659
15658
  import path22 from "path";
15659
+ import fs18 from "fs";
15660
+ var cachedGlobalMiddlewares = null;
15661
+ async function loadGlobalMiddlewares(projectRoot) {
15662
+ if (cachedGlobalMiddlewares !== null) {
15663
+ return cachedGlobalMiddlewares;
15664
+ }
15665
+ const globalMiddlewareFile = path22.join(projectRoot, "global.middleware.ts");
15666
+ const globalMiddlewareFileJs = path22.join(projectRoot, "global.middleware.js");
15667
+ const file = fs18.existsSync(globalMiddlewareFile) ? globalMiddlewareFile : fs18.existsSync(globalMiddlewareFileJs) ? globalMiddlewareFileJs : null;
15668
+ if (!file) {
15669
+ cachedGlobalMiddlewares = [];
15670
+ return cachedGlobalMiddlewares;
15671
+ }
15672
+ if (file.endsWith(".ts") || file.endsWith(".tsx")) {
15673
+ try {
15674
+ __require("tsx/cjs");
15675
+ } catch (e) {
15676
+ }
15677
+ }
15678
+ try {
15679
+ const mod = __require(file);
15680
+ const middlewares = mod?.globalMiddlewares;
15681
+ if (Array.isArray(middlewares)) {
15682
+ const validMiddlewares = [];
15683
+ for (let i = 0; i < middlewares.length; i++) {
15684
+ const mw = middlewares[i];
15685
+ if (typeof mw === "function") {
15686
+ validMiddlewares.push(mw);
15687
+ } else {
15688
+ console.warn(
15689
+ `[framework][global-middleware] Middleware at index ${i} in global.middleware.ts is not a function, skipping`
15690
+ );
15691
+ }
15692
+ }
15693
+ cachedGlobalMiddlewares = validMiddlewares;
15694
+ return cachedGlobalMiddlewares;
15695
+ } else if (middlewares !== void 0) {
15696
+ console.warn(
15697
+ "[framework][global-middleware] globalMiddlewares must be an array in global.middleware.ts, ignoring invalid value"
15698
+ );
15699
+ }
15700
+ } catch (error) {
15701
+ console.error("[framework][global-middleware] Error loading global.middleware.ts:", error);
15702
+ }
15703
+ cachedGlobalMiddlewares = [];
15704
+ return cachedGlobalMiddlewares;
15705
+ }
15706
+ async function runGlobalMiddlewares(ctx, globalMiddlewares) {
15707
+ for (const mw of globalMiddlewares) {
15708
+ try {
15709
+ await Promise.resolve(mw(ctx, async () => {
15710
+ }));
15711
+ } catch (error) {
15712
+ console.error("[framework][global-middleware] Error in global middleware:", error);
15713
+ continue;
15714
+ }
15715
+ if (ctx.res.headersSent) {
15716
+ return;
15717
+ }
15718
+ }
15719
+ }
15720
+
15721
+ // modules/server/handlers/ssg.ts
15722
+ import fs19 from "fs";
15723
+ import path23 from "path";
15660
15724
  var logger3 = createModuleLogger("ssg");
15661
15725
  function getSsgDirForPath(baseDir, urlPath) {
15662
15726
  const clean = urlPath === "/" ? "" : urlPath.replace(/^\/+/, "");
15663
- return path22.join(baseDir, clean);
15727
+ return path23.join(baseDir, clean);
15664
15728
  }
15665
15729
  function getSsgHtmlPath(baseDir, urlPath) {
15666
15730
  const dir = getSsgDirForPath(baseDir, urlPath);
15667
- return path22.join(dir, "index.html");
15731
+ return path23.join(dir, "index.html");
15668
15732
  }
15669
15733
  function getSsgDataPath(baseDir, urlPath) {
15670
15734
  const dir = getSsgDirForPath(baseDir, urlPath);
15671
- return path22.join(dir, "data.json");
15735
+ return path23.join(dir, "data.json");
15672
15736
  }
15673
15737
  function tryServeSsgHtml(res, ssgOutDir, urlPath) {
15674
15738
  const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
15675
- if (!fs18.existsSync(ssgHtmlPath)) {
15739
+ if (!fs19.existsSync(ssgHtmlPath)) {
15676
15740
  return false;
15677
15741
  }
15678
15742
  logger3.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
@@ -15682,17 +15746,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
15682
15746
  );
15683
15747
  res.statusCode = 200;
15684
15748
  res.setHeader("Content-Type", "text/html; charset=utf-8");
15685
- const stream = fs18.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
15749
+ const stream = fs19.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
15686
15750
  stream.pipe(res);
15687
15751
  return true;
15688
15752
  }
15689
15753
  function tryServeSsgData(res, ssgOutDir, urlPath) {
15690
15754
  const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
15691
- if (!fs18.existsSync(ssgDataPath)) {
15755
+ if (!fs19.existsSync(ssgDataPath)) {
15692
15756
  return false;
15693
15757
  }
15694
15758
  try {
15695
- const raw = fs18.readFileSync(ssgDataPath, "utf-8");
15759
+ const raw = fs19.readFileSync(ssgDataPath, "utf-8");
15696
15760
  res.setHeader("Content-Type", "application/json; charset=utf-8");
15697
15761
  res.status(200).end(raw);
15698
15762
  return true;
@@ -15704,7 +15768,7 @@ function tryServeSsgData(res, ssgOutDir, urlPath) {
15704
15768
 
15705
15769
  // modules/server/handlers/pages.ts
15706
15770
  init_globals();
15707
- import path23 from "path";
15771
+ import path24 from "path";
15708
15772
  function mergeMetadata(base, override) {
15709
15773
  if (!base && !override) return null;
15710
15774
  if (!base) return override;
@@ -15762,7 +15826,7 @@ async function renderNotFoundPage(notFoundPage, req, res, urlPath, finalUrlPath,
15762
15826
  } catch (error) {
15763
15827
  const reqLogger = getRequestLogger(req);
15764
15828
  const layoutFile = notFoundPage.layoutFiles[i];
15765
- const relativeLayoutPath = layoutFile ? path23.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
15829
+ const relativeLayoutPath = layoutFile ? path24.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
15766
15830
  reqLogger.error("Layout middleware failed for not-found page", error instanceof Error ? error : new Error(String(error)), {
15767
15831
  layoutIndex: i,
15768
15832
  layoutFile: relativeLayoutPath
@@ -15791,7 +15855,7 @@ async function renderNotFoundPage(notFoundPage, req, res, urlPath, finalUrlPath,
15791
15855
  } catch (error) {
15792
15856
  const reqLogger = getRequestLogger(req);
15793
15857
  const layoutFile = notFoundPage.layoutFiles[i];
15794
- const relativeLayoutPath = layoutFile ? path23.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
15858
+ const relativeLayoutPath = layoutFile ? path24.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
15795
15859
  reqLogger.warn("Layout server hook failed for not-found page", {
15796
15860
  error: error instanceof Error ? error.message : String(error),
15797
15861
  stack: error instanceof Error ? error.stack : void 0,
@@ -16028,6 +16092,11 @@ async function handlePageRequestInternal(options) {
16028
16092
  Redirect: (destination, permanent = false) => new RedirectResponse(destination, permanent),
16029
16093
  NotFound: () => new NotFoundResponse()
16030
16094
  };
16095
+ const globalMiddlewares = await loadGlobalMiddlewares(projectRoot || process.cwd());
16096
+ await runGlobalMiddlewares(ctx, globalMiddlewares);
16097
+ if (res.headersSent) {
16098
+ return;
16099
+ }
16031
16100
  await runRouteMiddlewares(route, ctx);
16032
16101
  if (res.headersSent) {
16033
16102
  return;
@@ -16048,7 +16117,7 @@ async function handlePageRequestInternal(options) {
16048
16117
  );
16049
16118
  } catch (error) {
16050
16119
  const layoutFile = route.layoutFiles[i];
16051
- const relativeLayoutPath = layoutFile ? path23.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16120
+ const relativeLayoutPath = layoutFile ? path24.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16052
16121
  reqLogger.error("Layout middleware failed", error instanceof Error ? error : new Error(String(error)), {
16053
16122
  route: route.pattern,
16054
16123
  layoutIndex: i,
@@ -16114,7 +16183,7 @@ async function handlePageRequestInternal(options) {
16114
16183
  }
16115
16184
  } catch (error) {
16116
16185
  const layoutFile = route.layoutFiles[i];
16117
- const relativeLayoutPath = layoutFile ? path23.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16186
+ const relativeLayoutPath = layoutFile ? path24.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16118
16187
  reqLogger.warn("Layout server hook failed", {
16119
16188
  error: error instanceof Error ? error.message : String(error),
16120
16189
  stack: error instanceof Error ? error.stack : void 0,
@@ -16177,7 +16246,7 @@ async function handlePageRequestInternal(options) {
16177
16246
  pageLoaderResult2.theme = theme;
16178
16247
  }
16179
16248
  } catch (error) {
16180
- const relativePagePath = route.pageFile ? path23.relative(projectRoot || process.cwd(), route.pageFile) : "unknown";
16249
+ const relativePagePath = route.pageFile ? path24.relative(projectRoot || process.cwd(), route.pageFile) : "unknown";
16181
16250
  reqLogger.error("Page server hook failed", {
16182
16251
  error: error instanceof Error ? error.message : String(error),
16183
16252
  stack: error instanceof Error ? error.stack : void 0,
@@ -16347,7 +16416,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
16347
16416
  );
16348
16417
  } catch (error2) {
16349
16418
  const layoutFile = errorPage.layoutFiles[i];
16350
- const relativeLayoutPath = layoutFile ? path23.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16419
+ const relativeLayoutPath = layoutFile ? path24.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16351
16420
  reqLogger.error("Layout middleware failed for error page", error2 instanceof Error ? error2 : new Error(String(error2)), {
16352
16421
  layoutIndex: i,
16353
16422
  layoutFile: relativeLayoutPath
@@ -16387,7 +16456,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
16387
16456
  }
16388
16457
  } catch (err) {
16389
16458
  const layoutFile = errorPage.layoutFiles[i];
16390
- const relativeLayoutPath = layoutFile ? path23.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16459
+ const relativeLayoutPath = layoutFile ? path24.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16391
16460
  reqLogger.warn("Layout server hook failed for error page", {
16392
16461
  error: err instanceof Error ? err.message : String(err),
16393
16462
  stack: err instanceof Error ? err.stack : void 0,
@@ -16710,7 +16779,7 @@ function validateRealtimeConfig(config) {
16710
16779
  }
16711
16780
 
16712
16781
  // modules/server/routes.ts
16713
- import path24 from "path";
16782
+ import path25 from "path";
16714
16783
  var cachedRewriteLoader = null;
16715
16784
  var cachedProjectRoot = null;
16716
16785
  var cachedIsDev = null;
@@ -16738,8 +16807,8 @@ function setupRoutes(options) {
16738
16807
  } = options;
16739
16808
  const routeChunks = routeLoader.loadRouteChunks();
16740
16809
  const rewriteLoader = getRewriteLoader(projectRoot, isDev);
16741
- const ssgOutDir = path24.join(
16742
- config ? getBuildDir(projectRoot, config) : path24.join(projectRoot, BUILD_FOLDER_NAME),
16810
+ const ssgOutDir = path25.join(
16811
+ config ? getBuildDir(projectRoot, config) : path25.join(projectRoot, BUILD_FOLDER_NAME),
16743
16812
  "ssg"
16744
16813
  );
16745
16814
  app.all("/api/*", async (req, res) => {
@@ -17968,8 +18037,8 @@ var setupApplication = async ({
17968
18037
 
17969
18038
  // src/server.ts
17970
18039
  import dotenv2 from "dotenv";
17971
- var envPath = path25.join(process.cwd(), ".env");
17972
- if (fs19.existsSync(envPath)) {
18040
+ var envPath = path26.join(process.cwd(), ".env");
18041
+ if (fs20.existsSync(envPath)) {
17973
18042
  dotenv2.config({ path: envPath });
17974
18043
  } else {
17975
18044
  dotenv2.config();
@@ -17990,8 +18059,8 @@ async function startServer(options = {}) {
17990
18059
  }
17991
18060
  const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
17992
18061
  const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
17993
- const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : path25.join(getBuildDir(projectRoot, config), "server"));
17994
- if (!isDev && !fs19.existsSync(appDir)) {
18062
+ const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : path26.join(getBuildDir(projectRoot, config), "server"));
18063
+ if (!isDev && !fs20.existsSync(appDir)) {
17995
18064
  logger4.error("Compiled directory not found", void 0, {
17996
18065
  buildDir: config.directories.build,
17997
18066
  appDir,
@@ -18062,10 +18131,10 @@ async function startProdServer(options = {}) {
18062
18131
  }
18063
18132
 
18064
18133
  // modules/build/ssg/builder.ts
18065
- import path28 from "path";
18134
+ import path29 from "path";
18066
18135
 
18067
18136
  // modules/build/ssg/path.ts
18068
- import path26 from "path";
18137
+ import path27 from "path";
18069
18138
  function buildPathFromPattern(pattern, params) {
18070
18139
  const segments = pattern.split("/").filter(Boolean);
18071
18140
  const parts = [];
@@ -18094,12 +18163,12 @@ function buildPathFromPattern(pattern, params) {
18094
18163
  }
18095
18164
  function pathToOutDir(baseDir, urlPath) {
18096
18165
  const clean = urlPath === "/" ? "" : urlPath.replace(/^\/+/, "");
18097
- return path26.join(baseDir, clean);
18166
+ return path27.join(baseDir, clean);
18098
18167
  }
18099
18168
 
18100
18169
  // modules/build/ssg/renderer.ts
18101
- import fs20 from "fs";
18102
- import path27 from "path";
18170
+ import fs21 from "fs";
18171
+ import path28 from "path";
18103
18172
  import { renderToString } from "react-dom/server";
18104
18173
  init_globals();
18105
18174
  async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params, config) {
@@ -18235,16 +18304,16 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params,
18235
18304
  const html = "<!DOCTYPE html>" + renderToString(documentTree);
18236
18305
  const dir = pathToOutDir(ssgOutDir, urlPath);
18237
18306
  ensureDir(dir);
18238
- const htmlFile = path27.join(dir, "index.html");
18239
- const dataFile = path27.join(dir, "data.json");
18240
- fs20.writeFileSync(htmlFile, html, "utf-8");
18241
- fs20.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
18307
+ const htmlFile = path28.join(dir, "index.html");
18308
+ const dataFile = path28.join(dir, "data.json");
18309
+ fs21.writeFileSync(htmlFile, html, "utf-8");
18310
+ fs21.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
18242
18311
  }
18243
18312
 
18244
18313
  // modules/build/ssg/builder.ts
18245
18314
  init_globals();
18246
18315
  async function buildStaticPages(projectRoot, routes, config) {
18247
- const ssgOutDir = path28.join(projectRoot, BUILD_FOLDER_NAME, "ssg");
18316
+ const ssgOutDir = path29.join(projectRoot, BUILD_FOLDER_NAME, "ssg");
18248
18317
  ensureDir(ssgOutDir);
18249
18318
  for (const route of routes) {
18250
18319
  if (route.dynamic !== "force-static") continue;
@@ -18299,36 +18368,36 @@ async function buildStaticPages(projectRoot, routes, config) {
18299
18368
  }
18300
18369
 
18301
18370
  // modules/build/bundler/server.ts
18302
- import path29 from "path";
18303
- import fs21 from "fs";
18371
+ import path30 from "path";
18372
+ import fs22 from "fs";
18304
18373
  import esbuild from "esbuild";
18305
18374
  init_globals();
18306
18375
  var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
18307
18376
  function createPathAliasPlugin(projectRoot, outDir) {
18308
18377
  const aliases = loadAliasesFromTsconfig(projectRoot);
18309
- const tsconfigPath = path29.join(projectRoot, "tsconfig.json");
18378
+ const tsconfigPath = path30.join(projectRoot, "tsconfig.json");
18310
18379
  let baseUrl = ".";
18311
- if (fs21.existsSync(tsconfigPath)) {
18380
+ if (fs22.existsSync(tsconfigPath)) {
18312
18381
  try {
18313
- const tsconfig = JSON.parse(fs21.readFileSync(tsconfigPath, "utf-8"));
18382
+ const tsconfig = JSON.parse(fs22.readFileSync(tsconfigPath, "utf-8"));
18314
18383
  baseUrl = tsconfig.compilerOptions?.baseUrl ?? ".";
18315
18384
  } catch {
18316
18385
  }
18317
18386
  }
18318
18387
  function resolveAliasToRelative(importPath, sourceFile) {
18319
- if (importPath.startsWith(".") || importPath.startsWith("/") || path29.isAbsolute(importPath) || importPath.includes("node_modules")) {
18388
+ if (importPath.startsWith(".") || importPath.startsWith("/") || path30.isAbsolute(importPath) || importPath.includes("node_modules")) {
18320
18389
  return null;
18321
18390
  }
18322
18391
  for (const [aliasKey, aliasPath] of Object.entries(aliases)) {
18323
18392
  if (importPath.startsWith(aliasKey + "/") || importPath === aliasKey) {
18324
18393
  const restPath = importPath.startsWith(aliasKey + "/") ? importPath.slice(aliasKey.length + 1) : "";
18325
- const resolvedPath = restPath ? path29.join(aliasPath, restPath) : aliasPath;
18394
+ const resolvedPath = restPath ? path30.join(aliasPath, restPath) : aliasPath;
18326
18395
  let actualPath = null;
18327
18396
  const extensions = [".ts", ".tsx", ".js", ".jsx", ".json"];
18328
- if (fs21.existsSync(resolvedPath) && fs21.statSync(resolvedPath).isDirectory()) {
18397
+ if (fs22.existsSync(resolvedPath) && fs22.statSync(resolvedPath).isDirectory()) {
18329
18398
  for (const ext of extensions) {
18330
- const indexPath = path29.join(resolvedPath, `index${ext}`);
18331
- if (fs21.existsSync(indexPath)) {
18399
+ const indexPath = path30.join(resolvedPath, `index${ext}`);
18400
+ if (fs22.existsSync(indexPath)) {
18332
18401
  actualPath = indexPath;
18333
18402
  break;
18334
18403
  }
@@ -18336,20 +18405,20 @@ function createPathAliasPlugin(projectRoot, outDir) {
18336
18405
  } else {
18337
18406
  for (const ext of extensions) {
18338
18407
  const filePath = resolvedPath + ext;
18339
- if (fs21.existsSync(filePath)) {
18408
+ if (fs22.existsSync(filePath)) {
18340
18409
  actualPath = filePath;
18341
18410
  break;
18342
18411
  }
18343
18412
  }
18344
- if (!actualPath && fs21.existsSync(resolvedPath)) {
18413
+ if (!actualPath && fs22.existsSync(resolvedPath)) {
18345
18414
  actualPath = resolvedPath;
18346
18415
  }
18347
18416
  }
18348
18417
  if (actualPath) {
18349
- const relativePath = path29.relative(outDir, actualPath);
18418
+ const relativePath = path30.relative(outDir, actualPath);
18350
18419
  const normalizedPath = relativePath.replace(/\\/g, "/");
18351
18420
  const finalPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
18352
- const ext = path29.extname(finalPath);
18421
+ const ext = path30.extname(finalPath);
18353
18422
  const pathWithoutExt = ext === ".json" ? finalPath : finalPath.slice(0, -ext.length);
18354
18423
  return pathWithoutExt;
18355
18424
  }
@@ -18361,13 +18430,13 @@ function createPathAliasPlugin(projectRoot, outDir) {
18361
18430
  name: "path-alias-resolver",
18362
18431
  setup(build) {
18363
18432
  build.onLoad({ filter: /\.(ts|tsx|js|jsx)$/ }, (args) => {
18364
- const fileName = path29.basename(args.path);
18433
+ const fileName = path30.basename(args.path);
18365
18434
  const isServerFile = SERVER_FILES.some((f) => fileName === `${f}.ts` || fileName === `${f}.tsx` || fileName === `${f}.js` || fileName === `${f}.jsx`);
18366
- const isInProjectRoot = path29.dirname(args.path) === projectRoot;
18435
+ const isInProjectRoot = path30.dirname(args.path) === projectRoot;
18367
18436
  if (!isServerFile || !isInProjectRoot) {
18368
18437
  return null;
18369
18438
  }
18370
- const contents = fs21.readFileSync(args.path, "utf-8");
18439
+ const contents = fs22.readFileSync(args.path, "utf-8");
18371
18440
  let transformed = contents;
18372
18441
  const aliasPatterns = Object.keys(aliases).sort((a, b) => b.length - a.length);
18373
18442
  for (const aliasKey of aliasPatterns) {
@@ -18387,7 +18456,7 @@ function createPathAliasPlugin(projectRoot, outDir) {
18387
18456
  }
18388
18457
  return {
18389
18458
  contents: transformed,
18390
- loader: path29.extname(args.path).slice(1)
18459
+ loader: path30.extname(args.path).slice(1)
18391
18460
  };
18392
18461
  });
18393
18462
  build.onResolve({ filter: /.*/ }, (args) => {
@@ -18406,9 +18475,9 @@ function createPathAliasPlugin(projectRoot, outDir) {
18406
18475
  function collectAppSources(appDir) {
18407
18476
  const entries = [];
18408
18477
  function walk(dir) {
18409
- const items = fs21.readdirSync(dir, { withFileTypes: true });
18478
+ const items = fs22.readdirSync(dir, { withFileTypes: true });
18410
18479
  for (const item of items) {
18411
- const full = path29.join(dir, item.name);
18480
+ const full = path30.join(dir, item.name);
18412
18481
  if (item.isDirectory()) {
18413
18482
  walk(full);
18414
18483
  continue;
@@ -18425,7 +18494,7 @@ function collectAppSources(appDir) {
18425
18494
  return entries;
18426
18495
  }
18427
18496
  async function buildServerApp(projectRoot, appDir) {
18428
- const outDir = path29.join(projectRoot, BUILD_FOLDER_NAME, "server");
18497
+ const outDir = path30.join(projectRoot, BUILD_FOLDER_NAME, "server");
18429
18498
  const entryPoints = collectAppSources(appDir);
18430
18499
  ensureDir(outDir);
18431
18500
  if (entryPoints.length === 0) {
@@ -18443,14 +18512,14 @@ async function buildServerApp(projectRoot, appDir) {
18443
18512
  bundle: true,
18444
18513
  splitting: false,
18445
18514
  logLevel: "info",
18446
- tsconfig: path29.join(projectRoot, "tsconfig.json"),
18515
+ tsconfig: path30.join(projectRoot, "tsconfig.json"),
18447
18516
  packages: "external"
18448
18517
  });
18449
18518
  const pathAliasPlugin = createPathAliasPlugin(projectRoot, outDir);
18450
18519
  for (const fileName of SERVER_FILES) {
18451
- const initTS = path29.join(projectRoot, `${fileName}.ts`);
18452
- const initJS = path29.join(outDir, `${fileName}.js`);
18453
- if (fs21.existsSync(initTS)) {
18520
+ const initTS = path30.join(projectRoot, `${fileName}.ts`);
18521
+ const initJS = path30.join(outDir, `${fileName}.js`);
18522
+ if (fs22.existsSync(initTS)) {
18454
18523
  await esbuild.build({
18455
18524
  entryPoints: [initTS],
18456
18525
  outfile: initJS,
@@ -18461,7 +18530,7 @@ async function buildServerApp(projectRoot, appDir) {
18461
18530
  sourcemap: true,
18462
18531
  bundle: false,
18463
18532
  logLevel: "info",
18464
- tsconfig: path29.join(projectRoot, "tsconfig.json"),
18533
+ tsconfig: path30.join(projectRoot, "tsconfig.json"),
18465
18534
  plugins: [pathAliasPlugin]
18466
18535
  });
18467
18536
  }
@@ -19748,11 +19817,11 @@ var ValidationError = class extends Error {
19748
19817
  format() {
19749
19818
  const formatted = {};
19750
19819
  for (const error of this.errors) {
19751
- const path30 = error.path.join(".");
19752
- if (!formatted[path30]) {
19753
- formatted[path30] = [];
19820
+ const path31 = error.path.join(".");
19821
+ if (!formatted[path31]) {
19822
+ formatted[path31] = [];
19754
19823
  }
19755
- formatted[path30].push(error.message);
19824
+ formatted[path31].push(error.message);
19756
19825
  }
19757
19826
  return formatted;
19758
19827
  }