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 +3 -1
- package/dist/CNAME +1 -0
- package/dist/assets/{runtime-worker-D8VYeuKv.js → runtime-worker-ujGAG2t7.js} +129 -6
- package/dist/assets/runtime-worker-ujGAG2t7.js.map +1 -0
- package/dist/index.cjs +125 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +130 -7
- package/dist/index.mjs.map +1 -1
- package/dist/og-image.png +0 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/shims/http.d.ts.map +1 -1
- package/dist/shims/ws.d.ts.map +1 -1
- package/dist/types/package-json.d.ts +1 -0
- package/dist/types/package-json.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/runtime.ts +177 -10
- package/src/shims/http.ts +4 -1
- package/src/shims/ws.ts +5 -2
- package/src/types/package-json.ts +1 -0
- package/dist/assets/runtime-worker-D8VYeuKv.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -3457,7 +3457,8 @@ let __tla = (async () => {
|
|
|
3457
3457
|
}, Symbol.toStringTag, {
|
|
3458
3458
|
value: "Module"
|
|
3459
3459
|
}));
|
|
3460
|
-
const
|
|
3460
|
+
const _isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
3461
|
+
const _BrowserWebSocket = _isBrowser && typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : null;
|
|
3461
3462
|
class IncomingMessage extends Readable {
|
|
3462
3463
|
constructor(socket) {
|
|
3463
3464
|
super();
|
|
@@ -6483,7 +6484,8 @@ let __tla = (async () => {
|
|
|
6483
6484
|
}, 100);
|
|
6484
6485
|
}
|
|
6485
6486
|
_connectNative() {
|
|
6486
|
-
const
|
|
6487
|
+
const isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
6488
|
+
const NativeWS = isBrowser2 && typeof globalThis.WebSocket === "function" && globalThis.WebSocket !== _WebSocket ? globalThis.WebSocket : null;
|
|
6487
6489
|
if (!NativeWS) {
|
|
6488
6490
|
setTimeout(() => {
|
|
6489
6491
|
this.readyState = _WebSocket.OPEN;
|
|
@@ -9587,9 +9589,6 @@ let __tla = (async () => {
|
|
|
9587
9589
|
return null;
|
|
9588
9590
|
};
|
|
9589
9591
|
const tryResolveFromNodeModules = (nodeModulesDir, moduleId) => {
|
|
9590
|
-
const fullPath = join(nodeModulesDir, moduleId);
|
|
9591
|
-
const resolved = tryResolveFile(fullPath);
|
|
9592
|
-
if (resolved) return resolved;
|
|
9593
9592
|
const parts = moduleId.split("/");
|
|
9594
9593
|
const pkgName = parts[0].startsWith("@") && parts.length > 1 ? `${parts[0]}/${parts[1]}` : parts[0];
|
|
9595
9594
|
const pkgRoot = join(nodeModulesDir, pkgName);
|
|
@@ -9611,12 +9610,21 @@ let __tla = (async () => {
|
|
|
9611
9610
|
}
|
|
9612
9611
|
}
|
|
9613
9612
|
if (pkgName === moduleId) {
|
|
9614
|
-
|
|
9613
|
+
let main;
|
|
9614
|
+
if (typeof pkg.browser === "string") {
|
|
9615
|
+
main = pkg.browser;
|
|
9616
|
+
}
|
|
9617
|
+
if (!main) {
|
|
9618
|
+
main = pkg.main || "index.js";
|
|
9619
|
+
}
|
|
9615
9620
|
const mainPath = join(pkgRoot, main);
|
|
9616
9621
|
const resolvedMain = tryResolveFile(mainPath);
|
|
9617
9622
|
if (resolvedMain) return resolvedMain;
|
|
9618
9623
|
}
|
|
9619
9624
|
}
|
|
9625
|
+
const fullPath = join(nodeModulesDir, moduleId);
|
|
9626
|
+
const resolved = tryResolveFile(fullPath);
|
|
9627
|
+
if (resolved) return resolved;
|
|
9620
9628
|
return null;
|
|
9621
9629
|
};
|
|
9622
9630
|
let searchDir = fromDir;
|
|
@@ -9864,6 +9872,7 @@ ${code}
|
|
|
9864
9872
|
setVFS$2(vfs2);
|
|
9865
9873
|
setVFS$1(vfs2);
|
|
9866
9874
|
setVFS(vfs2);
|
|
9875
|
+
this.setupStackTracePolyfill();
|
|
9867
9876
|
this.setupTextDecoderPolyfill();
|
|
9868
9877
|
}
|
|
9869
9878
|
setupTextDecoderPolyfill() {
|
|
@@ -9920,6 +9929,120 @@ ${code}
|
|
|
9920
9929
|
}
|
|
9921
9930
|
globalThis.TextDecoder = PolyfillTextDecoder;
|
|
9922
9931
|
}
|
|
9932
|
+
setupStackTracePolyfill() {
|
|
9933
|
+
if (typeof Error.captureStackTrace === "function") return;
|
|
9934
|
+
if (Error.stackTraceLimit === void 0) {
|
|
9935
|
+
Error.stackTraceLimit = 10;
|
|
9936
|
+
}
|
|
9937
|
+
function parseStack(stack) {
|
|
9938
|
+
if (!stack) return [];
|
|
9939
|
+
const frames = [];
|
|
9940
|
+
const lines = stack.split("\n");
|
|
9941
|
+
for (const raw of lines) {
|
|
9942
|
+
const line = raw.trim();
|
|
9943
|
+
if (!line || line.startsWith("Error") || line.startsWith("TypeError")) continue;
|
|
9944
|
+
let fn2 = "", file = "", lineNo = 0, colNo = 0;
|
|
9945
|
+
const safariMatch = line.match(/^(.*)@(.*?):(\d+):(\d+)$/);
|
|
9946
|
+
if (safariMatch) {
|
|
9947
|
+
fn2 = safariMatch[1] || "";
|
|
9948
|
+
file = safariMatch[2];
|
|
9949
|
+
lineNo = parseInt(safariMatch[3], 10);
|
|
9950
|
+
colNo = parseInt(safariMatch[4], 10);
|
|
9951
|
+
frames.push({
|
|
9952
|
+
fn: fn2,
|
|
9953
|
+
file,
|
|
9954
|
+
line: lineNo,
|
|
9955
|
+
col: colNo
|
|
9956
|
+
});
|
|
9957
|
+
continue;
|
|
9958
|
+
}
|
|
9959
|
+
const chromeMatch = line.match(/^at\s+(?:(.+?)\s+\()?(.*?):(\d+):(\d+)\)?$/);
|
|
9960
|
+
if (chromeMatch) {
|
|
9961
|
+
fn2 = chromeMatch[1] || "";
|
|
9962
|
+
file = chromeMatch[2];
|
|
9963
|
+
lineNo = parseInt(chromeMatch[3], 10);
|
|
9964
|
+
colNo = parseInt(chromeMatch[4], 10);
|
|
9965
|
+
frames.push({
|
|
9966
|
+
fn: fn2,
|
|
9967
|
+
file,
|
|
9968
|
+
line: lineNo,
|
|
9969
|
+
col: colNo
|
|
9970
|
+
});
|
|
9971
|
+
continue;
|
|
9972
|
+
}
|
|
9973
|
+
}
|
|
9974
|
+
return frames;
|
|
9975
|
+
}
|
|
9976
|
+
function createCallSite(frame) {
|
|
9977
|
+
return {
|
|
9978
|
+
getFileName: () => frame.file || null,
|
|
9979
|
+
getLineNumber: () => frame.line || null,
|
|
9980
|
+
getColumnNumber: () => frame.col || null,
|
|
9981
|
+
getFunctionName: () => frame.fn || null,
|
|
9982
|
+
getMethodName: () => frame.fn || null,
|
|
9983
|
+
getTypeName: () => null,
|
|
9984
|
+
getThis: () => void 0,
|
|
9985
|
+
getFunction: () => void 0,
|
|
9986
|
+
getEvalOrigin: () => void 0,
|
|
9987
|
+
isNative: () => false,
|
|
9988
|
+
isConstructor: () => false,
|
|
9989
|
+
isToplevel: () => !frame.fn,
|
|
9990
|
+
isEval: () => false,
|
|
9991
|
+
toString: () => frame.fn ? `${frame.fn} (${frame.file}:${frame.line}:${frame.col})` : `${frame.file}:${frame.line}:${frame.col}`
|
|
9992
|
+
};
|
|
9993
|
+
}
|
|
9994
|
+
function buildCallSites(stack, constructorOpt) {
|
|
9995
|
+
const frames = parseStack(stack);
|
|
9996
|
+
let startIdx = 0;
|
|
9997
|
+
if (constructorOpt && constructorOpt.name) {
|
|
9998
|
+
for (let i2 = 0; i2 < frames.length; i2++) {
|
|
9999
|
+
if (frames[i2].fn === constructorOpt.name) {
|
|
10000
|
+
startIdx = i2 + 1;
|
|
10001
|
+
break;
|
|
10002
|
+
}
|
|
10003
|
+
}
|
|
10004
|
+
}
|
|
10005
|
+
return frames.slice(startIdx).map(createCallSite);
|
|
10006
|
+
}
|
|
10007
|
+
const stackSymbol = Symbol("rawStack");
|
|
10008
|
+
Object.defineProperty(Error.prototype, "stack", {
|
|
10009
|
+
get() {
|
|
10010
|
+
const rawStack = this[stackSymbol];
|
|
10011
|
+
if (rawStack !== void 0 && typeof Error.prepareStackTrace === "function") {
|
|
10012
|
+
const callSites = buildCallSites(rawStack);
|
|
10013
|
+
try {
|
|
10014
|
+
return Error.prepareStackTrace(this, callSites);
|
|
10015
|
+
} catch {
|
|
10016
|
+
return rawStack;
|
|
10017
|
+
}
|
|
10018
|
+
}
|
|
10019
|
+
return rawStack;
|
|
10020
|
+
},
|
|
10021
|
+
set(value2) {
|
|
10022
|
+
this[stackSymbol] = value2;
|
|
10023
|
+
},
|
|
10024
|
+
configurable: true,
|
|
10025
|
+
enumerable: false
|
|
10026
|
+
});
|
|
10027
|
+
Error.captureStackTrace = function(target, constructorOpt) {
|
|
10028
|
+
const savedPrepare = Error.prepareStackTrace;
|
|
10029
|
+
Error.prepareStackTrace = void 0;
|
|
10030
|
+
const err = new Error();
|
|
10031
|
+
const rawStack = err.stack || "";
|
|
10032
|
+
Error.prepareStackTrace = savedPrepare;
|
|
10033
|
+
if (typeof savedPrepare === "function") {
|
|
10034
|
+
const callSites = buildCallSites(rawStack, constructorOpt);
|
|
10035
|
+
try {
|
|
10036
|
+
target.stack = savedPrepare(target, callSites);
|
|
10037
|
+
} catch (e) {
|
|
10038
|
+
console.warn("[almostnode] Error.prepareStackTrace threw:", e);
|
|
10039
|
+
target.stack = rawStack;
|
|
10040
|
+
}
|
|
10041
|
+
} else {
|
|
10042
|
+
target.stack = rawStack;
|
|
10043
|
+
}
|
|
10044
|
+
};
|
|
10045
|
+
}
|
|
9923
10046
|
execute(code, filename = "/index.js") {
|
|
9924
10047
|
const dirname$1 = dirname(filename);
|
|
9925
10048
|
this.vfs.writeFileSync(filename, code);
|
|
@@ -10042,7 +10165,7 @@ while (true) {
|
|
|
10042
10165
|
__publicField(this, "deleteListener", null);
|
|
10043
10166
|
this.vfs = vfs2;
|
|
10044
10167
|
this.options = options2;
|
|
10045
|
-
this.worker = new Worker(new URL("/assets/runtime-worker-
|
|
10168
|
+
this.worker = new Worker(new URL("/assets/runtime-worker-ujGAG2t7.js", import.meta.url), {
|
|
10046
10169
|
type: "module"
|
|
10047
10170
|
});
|
|
10048
10171
|
this.workerApi = wrap(this.worker);
|