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/README.md CHANGED
@@ -8,6 +8,8 @@ A lightweight, browser-native Node.js runtime environment. Run Node.js code, ins
8
8
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
9
9
  [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D20-green.svg)](https://nodejs.org/)
10
10
 
11
+ Built by the creators of [Macaly.com](https://macaly.com) — a tool that lets anyone build websites and web apps, even without coding experience. Think Claude Code for non-developers.
12
+
11
13
  > **Warning:** This project is experimental and may contain bugs. Use with caution in production environments.
12
14
 
13
15
  ---
@@ -909,5 +911,5 @@ MIT License - see [LICENSE](LICENSE) for details.
909
911
  ---
910
912
 
911
913
  <p align="center">
912
- Made with care for the browser
914
+ Built by the creators of <a href="https://macaly.com">Macaly.com</a>
913
915
  </p>
package/dist/CNAME ADDED
@@ -0,0 +1 @@
1
+ almostnode.dev
@@ -3757,7 +3757,8 @@
3757
3757
  timingSafeEqual: timingSafeEqual,
3758
3758
  verify: verify
3759
3759
  });
3760
- const _BrowserWebSocket = typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : null;
3760
+ const _isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
3761
+ const _BrowserWebSocket = _isBrowser && typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : null;
3761
3762
  class IncomingMessage extends Readable {
3762
3763
  httpVersion = "1.1";
3763
3764
  httpVersionMajor = 1;
@@ -57018,7 +57019,8 @@ sys 0m0.000s
57018
57019
  }, 100);
57019
57020
  }
57020
57021
  _connectNative() {
57021
- const NativeWS = typeof globalThis.WebSocket === "function" && globalThis.WebSocket !== WebSocket ? globalThis.WebSocket : null;
57022
+ const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
57023
+ const NativeWS = isBrowser && typeof globalThis.WebSocket === "function" && globalThis.WebSocket !== WebSocket ? globalThis.WebSocket : null;
57022
57024
  if (!NativeWS) {
57023
57025
  setTimeout(()=>{
57024
57026
  this.readyState = WebSocket.OPEN;
@@ -60029,9 +60031,6 @@ sys 0m0.000s
60029
60031
  return null;
60030
60032
  };
60031
60033
  const tryResolveFromNodeModules = (nodeModulesDir, moduleId)=>{
60032
- const fullPath = join$1(nodeModulesDir, moduleId);
60033
- const resolved = tryResolveFile(fullPath);
60034
- if (resolved) return resolved;
60035
60034
  const parts = moduleId.split("/");
60036
60035
  const pkgName = parts[0].startsWith("@") && parts.length > 1 ? `${parts[0]}/${parts[1]}` : parts[0];
60037
60036
  const pkgRoot = join$1(nodeModulesDir, pkgName);
@@ -60052,12 +60051,21 @@ sys 0m0.000s
60052
60051
  } catch {}
60053
60052
  }
60054
60053
  if (pkgName === moduleId) {
60055
- const main = pkg.main || "index.js";
60054
+ let main;
60055
+ if (typeof pkg.browser === "string") {
60056
+ main = pkg.browser;
60057
+ }
60058
+ if (!main) {
60059
+ main = pkg.main || "index.js";
60060
+ }
60056
60061
  const mainPath = join$1(pkgRoot, main);
60057
60062
  const resolvedMain = tryResolveFile(mainPath);
60058
60063
  if (resolvedMain) return resolvedMain;
60059
60064
  }
60060
60065
  }
60066
+ const fullPath = join$1(nodeModulesDir, moduleId);
60067
+ const resolved = tryResolveFile(fullPath);
60068
+ if (resolved) return resolved;
60061
60069
  return null;
60062
60070
  };
60063
60071
  let searchDir = fromDir;
@@ -60303,6 +60311,7 @@ ${code}
60303
60311
  setVFS$2(vfs2);
60304
60312
  setVFS$1(vfs2);
60305
60313
  setVFS(vfs2);
60314
+ this.setupStackTracePolyfill();
60306
60315
  this.setupTextDecoderPolyfill();
60307
60316
  }
60308
60317
  setupTextDecoderPolyfill() {
@@ -60357,6 +60366,120 @@ ${code}
60357
60366
  }
60358
60367
  globalThis.TextDecoder = PolyfillTextDecoder;
60359
60368
  }
60369
+ setupStackTracePolyfill() {
60370
+ if (typeof Error.captureStackTrace === "function") return;
60371
+ if (Error.stackTraceLimit === void 0) {
60372
+ Error.stackTraceLimit = 10;
60373
+ }
60374
+ function parseStack(stack) {
60375
+ if (!stack) return [];
60376
+ const frames = [];
60377
+ const lines = stack.split("\n");
60378
+ for (const raw of lines){
60379
+ const line = raw.trim();
60380
+ if (!line || line.startsWith("Error") || line.startsWith("TypeError")) continue;
60381
+ let fn2 = "", file = "", lineNo = 0, colNo = 0;
60382
+ const safariMatch = line.match(/^(.*)@(.*?):(\d+):(\d+)$/);
60383
+ if (safariMatch) {
60384
+ fn2 = safariMatch[1] || "";
60385
+ file = safariMatch[2];
60386
+ lineNo = parseInt(safariMatch[3], 10);
60387
+ colNo = parseInt(safariMatch[4], 10);
60388
+ frames.push({
60389
+ fn: fn2,
60390
+ file,
60391
+ line: lineNo,
60392
+ col: colNo
60393
+ });
60394
+ continue;
60395
+ }
60396
+ const chromeMatch = line.match(/^at\s+(?:(.+?)\s+\()?(.*?):(\d+):(\d+)\)?$/);
60397
+ if (chromeMatch) {
60398
+ fn2 = chromeMatch[1] || "";
60399
+ file = chromeMatch[2];
60400
+ lineNo = parseInt(chromeMatch[3], 10);
60401
+ colNo = parseInt(chromeMatch[4], 10);
60402
+ frames.push({
60403
+ fn: fn2,
60404
+ file,
60405
+ line: lineNo,
60406
+ col: colNo
60407
+ });
60408
+ continue;
60409
+ }
60410
+ }
60411
+ return frames;
60412
+ }
60413
+ function createCallSite(frame) {
60414
+ return {
60415
+ getFileName: ()=>frame.file || null,
60416
+ getLineNumber: ()=>frame.line || null,
60417
+ getColumnNumber: ()=>frame.col || null,
60418
+ getFunctionName: ()=>frame.fn || null,
60419
+ getMethodName: ()=>frame.fn || null,
60420
+ getTypeName: ()=>null,
60421
+ getThis: ()=>void 0,
60422
+ getFunction: ()=>void 0,
60423
+ getEvalOrigin: ()=>void 0,
60424
+ isNative: ()=>false,
60425
+ isConstructor: ()=>false,
60426
+ isToplevel: ()=>!frame.fn,
60427
+ isEval: ()=>false,
60428
+ toString: ()=>frame.fn ? `${frame.fn} (${frame.file}:${frame.line}:${frame.col})` : `${frame.file}:${frame.line}:${frame.col}`
60429
+ };
60430
+ }
60431
+ function buildCallSites(stack, constructorOpt) {
60432
+ const frames = parseStack(stack);
60433
+ let startIdx = 0;
60434
+ if (constructorOpt && constructorOpt.name) {
60435
+ for(let i = 0; i < frames.length; i++){
60436
+ if (frames[i].fn === constructorOpt.name) {
60437
+ startIdx = i + 1;
60438
+ break;
60439
+ }
60440
+ }
60441
+ }
60442
+ return frames.slice(startIdx).map(createCallSite);
60443
+ }
60444
+ const stackSymbol = Symbol("rawStack");
60445
+ Object.defineProperty(Error.prototype, "stack", {
60446
+ get () {
60447
+ const rawStack = this[stackSymbol];
60448
+ if (rawStack !== void 0 && typeof Error.prepareStackTrace === "function") {
60449
+ const callSites = buildCallSites(rawStack);
60450
+ try {
60451
+ return Error.prepareStackTrace(this, callSites);
60452
+ } catch {
60453
+ return rawStack;
60454
+ }
60455
+ }
60456
+ return rawStack;
60457
+ },
60458
+ set (value) {
60459
+ this[stackSymbol] = value;
60460
+ },
60461
+ configurable: true,
60462
+ enumerable: false
60463
+ });
60464
+ Error.captureStackTrace = function(target, constructorOpt) {
60465
+ const savedPrepare = Error.prepareStackTrace;
60466
+ Error.prepareStackTrace = void 0;
60467
+ const err = new Error();
60468
+ const rawStack = err.stack || "";
60469
+ Error.prepareStackTrace = savedPrepare;
60470
+ if (typeof savedPrepare === "function") {
60471
+ const callSites = buildCallSites(rawStack, constructorOpt);
60472
+ try {
60473
+ target.stack = savedPrepare(target, callSites);
60474
+ } catch (e) {
60475
+ console.warn("[almostnode] Error.prepareStackTrace threw:", e);
60476
+ target.stack = rawStack;
60477
+ }
60478
+ } else {
60479
+ target.stack = rawStack;
60480
+ }
60481
+ };
60482
+ }
60360
60483
  execute(code, filename = "/index.js") {
60361
60484
  const dirname$1 = dirname(filename);
60362
60485
  this.vfs.writeFileSync(filename, code);