almostnode 0.2.8 → 0.2.9

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.cjs CHANGED
@@ -3476,7 +3476,8 @@ const cryptoShim = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
3476
3476
  verify
3477
3477
  }, Symbol.toStringTag, { value: 'Module' }));
3478
3478
 
3479
- const _BrowserWebSocket = typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : null;
3479
+ const _isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
3480
+ const _BrowserWebSocket = _isBrowser && typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : null;
3480
3481
  class IncomingMessage extends Readable {
3481
3482
  httpVersion = "1.1";
3482
3483
  httpVersionMajor = 1;
@@ -6454,7 +6455,8 @@ class WebSocket extends EventEmitter {
6454
6455
  }, 100);
6455
6456
  }
6456
6457
  _connectNative() {
6457
- const NativeWS = typeof globalThis.WebSocket === "function" && globalThis.WebSocket !== WebSocket ? globalThis.WebSocket : null;
6458
+ const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
6459
+ const NativeWS = isBrowser && typeof globalThis.WebSocket === "function" && globalThis.WebSocket !== WebSocket ? globalThis.WebSocket : null;
6458
6460
  if (!NativeWS) {
6459
6461
  setTimeout(() => {
6460
6462
  this.readyState = WebSocket.OPEN;
@@ -9453,9 +9455,6 @@ function createRequire(vfs, fsShim, process, currentDir, moduleCache, options, p
9453
9455
  return null;
9454
9456
  };
9455
9457
  const tryResolveFromNodeModules = (nodeModulesDir, moduleId) => {
9456
- const fullPath = join(nodeModulesDir, moduleId);
9457
- const resolved = tryResolveFile(fullPath);
9458
- if (resolved) return resolved;
9459
9458
  const parts = moduleId.split("/");
9460
9459
  const pkgName = parts[0].startsWith("@") && parts.length > 1 ? `${parts[0]}/${parts[1]}` : parts[0];
9461
9460
  const pkgRoot = join(nodeModulesDir, pkgName);
@@ -9475,12 +9474,21 @@ function createRequire(vfs, fsShim, process, currentDir, moduleCache, options, p
9475
9474
  }
9476
9475
  }
9477
9476
  if (pkgName === moduleId) {
9478
- const main = pkg.main || "index.js";
9477
+ let main;
9478
+ if (typeof pkg.browser === "string") {
9479
+ main = pkg.browser;
9480
+ }
9481
+ if (!main) {
9482
+ main = pkg.main || "index.js";
9483
+ }
9479
9484
  const mainPath = join(pkgRoot, main);
9480
9485
  const resolvedMain = tryResolveFile(mainPath);
9481
9486
  if (resolvedMain) return resolvedMain;
9482
9487
  }
9483
9488
  }
9489
+ const fullPath = join(nodeModulesDir, moduleId);
9490
+ const resolved = tryResolveFile(fullPath);
9491
+ if (resolved) return resolved;
9484
9492
  return null;
9485
9493
  };
9486
9494
  let searchDir = fromDir;
@@ -9746,6 +9754,7 @@ class Runtime {
9746
9754
  setVFS$2(vfs2);
9747
9755
  setVFS$1(vfs2);
9748
9756
  setVFS(vfs2);
9757
+ this.setupStackTracePolyfill();
9749
9758
  this.setupTextDecoderPolyfill();
9750
9759
  }
9751
9760
  /**
@@ -9803,6 +9812,115 @@ class Runtime {
9803
9812
  }
9804
9813
  globalThis.TextDecoder = PolyfillTextDecoder;
9805
9814
  }
9815
+ /**
9816
+ * Polyfill V8's Error.captureStackTrace and Error.prepareStackTrace for Safari/WebKit.
9817
+ * Express's `depd` and other npm packages use these V8-specific APIs which don't
9818
+ * exist in Safari, causing "callSite.getFileName is not a function" errors.
9819
+ */
9820
+ setupStackTracePolyfill() {
9821
+ if (typeof Error.captureStackTrace === "function") return;
9822
+ if (Error.stackTraceLimit === void 0) {
9823
+ Error.stackTraceLimit = 10;
9824
+ }
9825
+ function parseStack(stack) {
9826
+ if (!stack) return [];
9827
+ const frames = [];
9828
+ const lines = stack.split("\n");
9829
+ for (const raw of lines) {
9830
+ const line = raw.trim();
9831
+ if (!line || line.startsWith("Error") || line.startsWith("TypeError")) continue;
9832
+ let fn2 = "", file = "", lineNo = 0, colNo = 0;
9833
+ const safariMatch = line.match(/^(.*)@(.*?):(\d+):(\d+)$/);
9834
+ if (safariMatch) {
9835
+ fn2 = safariMatch[1] || "";
9836
+ file = safariMatch[2];
9837
+ lineNo = parseInt(safariMatch[3], 10);
9838
+ colNo = parseInt(safariMatch[4], 10);
9839
+ frames.push({ fn: fn2, file, line: lineNo, col: colNo });
9840
+ continue;
9841
+ }
9842
+ const chromeMatch = line.match(/^at\s+(?:(.+?)\s+\()?(.*?):(\d+):(\d+)\)?$/);
9843
+ if (chromeMatch) {
9844
+ fn2 = chromeMatch[1] || "";
9845
+ file = chromeMatch[2];
9846
+ lineNo = parseInt(chromeMatch[3], 10);
9847
+ colNo = parseInt(chromeMatch[4], 10);
9848
+ frames.push({ fn: fn2, file, line: lineNo, col: colNo });
9849
+ continue;
9850
+ }
9851
+ }
9852
+ return frames;
9853
+ }
9854
+ function createCallSite(frame) {
9855
+ return {
9856
+ getFileName: () => frame.file || null,
9857
+ getLineNumber: () => frame.line || null,
9858
+ getColumnNumber: () => frame.col || null,
9859
+ getFunctionName: () => frame.fn || null,
9860
+ getMethodName: () => frame.fn || null,
9861
+ getTypeName: () => null,
9862
+ getThis: () => void 0,
9863
+ getFunction: () => void 0,
9864
+ getEvalOrigin: () => void 0,
9865
+ isNative: () => false,
9866
+ isConstructor: () => false,
9867
+ isToplevel: () => !frame.fn,
9868
+ isEval: () => false,
9869
+ toString: () => frame.fn ? `${frame.fn} (${frame.file}:${frame.line}:${frame.col})` : `${frame.file}:${frame.line}:${frame.col}`
9870
+ };
9871
+ }
9872
+ function buildCallSites(stack, constructorOpt) {
9873
+ const frames = parseStack(stack);
9874
+ let startIdx = 0;
9875
+ if (constructorOpt && constructorOpt.name) {
9876
+ for (let i = 0; i < frames.length; i++) {
9877
+ if (frames[i].fn === constructorOpt.name) {
9878
+ startIdx = i + 1;
9879
+ break;
9880
+ }
9881
+ }
9882
+ }
9883
+ return frames.slice(startIdx).map(createCallSite);
9884
+ }
9885
+ const stackSymbol = Symbol("rawStack");
9886
+ Object.defineProperty(Error.prototype, "stack", {
9887
+ get() {
9888
+ const rawStack = this[stackSymbol];
9889
+ if (rawStack !== void 0 && typeof Error.prepareStackTrace === "function") {
9890
+ const callSites = buildCallSites(rawStack);
9891
+ try {
9892
+ return Error.prepareStackTrace(this, callSites);
9893
+ } catch {
9894
+ return rawStack;
9895
+ }
9896
+ }
9897
+ return rawStack;
9898
+ },
9899
+ set(value) {
9900
+ this[stackSymbol] = value;
9901
+ },
9902
+ configurable: true,
9903
+ enumerable: false
9904
+ });
9905
+ Error.captureStackTrace = function(target, constructorOpt) {
9906
+ const savedPrepare = Error.prepareStackTrace;
9907
+ Error.prepareStackTrace = void 0;
9908
+ const err = new Error();
9909
+ const rawStack = err.stack || "";
9910
+ Error.prepareStackTrace = savedPrepare;
9911
+ if (typeof savedPrepare === "function") {
9912
+ const callSites = buildCallSites(rawStack, constructorOpt);
9913
+ try {
9914
+ target.stack = savedPrepare(target, callSites);
9915
+ } catch (e) {
9916
+ console.warn("[almostnode] Error.prepareStackTrace threw:", e);
9917
+ target.stack = rawStack;
9918
+ }
9919
+ } else {
9920
+ target.stack = rawStack;
9921
+ }
9922
+ };
9923
+ }
9806
9924
  /**
9807
9925
  * Execute code as a module (synchronous - backward compatible)
9808
9926
  */
@@ -9998,7 +10116,7 @@ class WorkerRuntime {
9998
10116
  this.vfs = vfs;
9999
10117
  this.options = options;
10000
10118
  this.worker = new Worker(
10001
- new URL(/* @vite-ignore */ "/assets/runtime-worker-D8VYeuKv.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),
10119
+ new URL(/* @vite-ignore */ "/assets/runtime-worker-ujGAG2t7.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),
10002
10120
  { type: "module" }
10003
10121
  );
10004
10122
  this.workerApi = comlink.wrap(this.worker);