@volter/tabnode 0.5.25 → 0.5.27

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.
@@ -21146,10 +21146,17 @@ var implementation$1 = function bind2(that) {
21146
21146
  var implementation = implementation$1;
21147
21147
  var functionBind = Function.prototype.bind || implementation;
21148
21148
  var functionCall = Function.prototype.call;
21149
- var functionApply = Function.prototype.apply;
21149
+ var functionApply;
21150
+ var hasRequiredFunctionApply;
21151
+ function requireFunctionApply() {
21152
+ if (hasRequiredFunctionApply) return functionApply;
21153
+ hasRequiredFunctionApply = 1;
21154
+ functionApply = Function.prototype.apply;
21155
+ return functionApply;
21156
+ }
21150
21157
  var reflectApply = typeof Reflect !== "undefined" && Reflect && Reflect.apply;
21151
21158
  var bind$2 = functionBind;
21152
- var $apply$1 = functionApply;
21159
+ var $apply$1 = requireFunctionApply();
21153
21160
  var $call$2 = functionCall;
21154
21161
  var $reflectApply = reflectApply;
21155
21162
  var actualApply = $reflectApply || bind$2.call($call$2, $apply$1);
@@ -21269,7 +21276,7 @@ var hasSymbols = requireHasSymbols()();
21269
21276
  var getProto = requireGetProto();
21270
21277
  var $ObjectGPO = requireObject_getPrototypeOf();
21271
21278
  var $ReflectGPO = requireReflect_getPrototypeOf();
21272
- var $apply = functionApply;
21279
+ var $apply = requireFunctionApply();
21273
21280
  var $call = functionCall;
21274
21281
  var needsEval = {};
21275
21282
  var TypedArray = typeof Uint8Array === "undefined" || !getProto ? undefined$1 : getProto(Uint8Array);
@@ -21910,7 +21917,7 @@ function requireApplyBind() {
21910
21917
  if (hasRequiredApplyBind) return applyBind;
21911
21918
  hasRequiredApplyBind = 1;
21912
21919
  var bind3 = functionBind;
21913
- var $apply2 = functionApply;
21920
+ var $apply2 = requireFunctionApply();
21914
21921
  var actualApply$1 = actualApply;
21915
21922
  applyBind = function applyBind2() {
21916
21923
  return actualApply$1(bind3, $apply2, arguments);
@@ -22521,9 +22528,9 @@ Sha256$1.prototype._hash = function() {
22521
22528
  H.writeInt32BE(this._h, 28);
22522
22529
  return H;
22523
22530
  };
22524
- var sha256 = Sha256$1;
22531
+ var sha256$1 = Sha256$1;
22525
22532
  var inherits$2 = inherits_browserExports;
22526
- var Sha256 = sha256;
22533
+ var Sha256 = sha256$1;
22527
22534
  var Hash$2 = hash$1;
22528
22535
  var Buffer$3 = safeBufferExports.Buffer;
22529
22536
  var W$3 = new Array(64);
@@ -22949,7 +22956,7 @@ var sha384 = Sha384;
22949
22956
  module.exports.sha = sha;
22950
22957
  module.exports.sha1 = sha1;
22951
22958
  module.exports.sha224 = sha224;
22952
- module.exports.sha256 = sha256;
22959
+ module.exports.sha256 = sha256$1;
22953
22960
  module.exports.sha384 = sha384;
22954
22961
  module.exports.sha512 = sha512;
22955
22962
  })(sha_js);
@@ -23003,9 +23010,27 @@ function clean(...arrays) {
23003
23010
  function createView(arr) {
23004
23011
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
23005
23012
  }
23013
+ function rotr(word, shift) {
23014
+ return word << 32 - shift | word >>> shift;
23015
+ }
23006
23016
  function rotl(word, shift) {
23007
23017
  return word << shift | word >>> 32 - shift >>> 0;
23008
23018
  }
23019
+ const hasHexBuiltin = /* @__PURE__ */ (() => (
23020
+ // @ts-ignore
23021
+ typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
23022
+ ))();
23023
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i10) => i10.toString(16).padStart(2, "0"));
23024
+ function bytesToHex(bytes2) {
23025
+ abytes(bytes2);
23026
+ if (hasHexBuiltin)
23027
+ return bytes2.toHex();
23028
+ let hex = "";
23029
+ for (let i10 = 0; i10 < bytes2.length; i10++) {
23030
+ hex += hexes[bytes2[i10]];
23031
+ }
23032
+ return hex;
23033
+ }
23009
23034
  function checkOpts(defaults2, opts, title = "opts") {
23010
23035
  aobject(defaults2, "defaults");
23011
23036
  if (opts !== void 0)
@@ -23026,9 +23051,17 @@ function createHasher(hashCons, info = {}) {
23026
23051
  Object.assign(hashC, info);
23027
23052
  return Object.freeze(hashC);
23028
23053
  }
23054
+ const oidNist = (suffix) => ({
23055
+ // Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
23056
+ // Larger suffix values would need base-128 OID encoding and a different length byte.
23057
+ oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
23058
+ });
23029
23059
  function Chi(a, b, c) {
23030
23060
  return a & b ^ ~a & c;
23031
23061
  }
23062
+ function Maj(a, b, c) {
23063
+ return a & b ^ a & c ^ b & c;
23064
+ }
23032
23065
  class HashMD {
23033
23066
  constructor(blockLen, outputLen, padOffset, isLE) {
23034
23067
  __publicField(this, "blockLen");
@@ -23124,6 +23157,16 @@ class HashMD {
23124
23157
  return this._cloneInto();
23125
23158
  }
23126
23159
  }
23160
+ const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
23161
+ 1779033703,
23162
+ 3144134277,
23163
+ 1013904242,
23164
+ 2773480762,
23165
+ 1359893119,
23166
+ 2600822924,
23167
+ 528734635,
23168
+ 1541459225
23169
+ ]);
23127
23170
  const SHA1_IV = /* @__PURE__ */ Uint32Array.from([
23128
23171
  1732584193,
23129
23172
  4023233417,
@@ -32103,6 +32146,169 @@ function simpleHash(str) {
32103
32146
  }
32104
32147
  return hash2.toString(36);
32105
32148
  }
32149
+ const SHA256_K = /* @__PURE__ */ Uint32Array.from([
32150
+ 1116352408,
32151
+ 1899447441,
32152
+ 3049323471,
32153
+ 3921009573,
32154
+ 961987163,
32155
+ 1508970993,
32156
+ 2453635748,
32157
+ 2870763221,
32158
+ 3624381080,
32159
+ 310598401,
32160
+ 607225278,
32161
+ 1426881987,
32162
+ 1925078388,
32163
+ 2162078206,
32164
+ 2614888103,
32165
+ 3248222580,
32166
+ 3835390401,
32167
+ 4022224774,
32168
+ 264347078,
32169
+ 604807628,
32170
+ 770255983,
32171
+ 1249150122,
32172
+ 1555081692,
32173
+ 1996064986,
32174
+ 2554220882,
32175
+ 2821834349,
32176
+ 2952996808,
32177
+ 3210313671,
32178
+ 3336571891,
32179
+ 3584528711,
32180
+ 113926993,
32181
+ 338241895,
32182
+ 666307205,
32183
+ 773529912,
32184
+ 1294757372,
32185
+ 1396182291,
32186
+ 1695183700,
32187
+ 1986661051,
32188
+ 2177026350,
32189
+ 2456956037,
32190
+ 2730485921,
32191
+ 2820302411,
32192
+ 3259730800,
32193
+ 3345764771,
32194
+ 3516065817,
32195
+ 3600352804,
32196
+ 4094571909,
32197
+ 275423344,
32198
+ 430227734,
32199
+ 506948616,
32200
+ 659060556,
32201
+ 883997877,
32202
+ 958139571,
32203
+ 1322822218,
32204
+ 1537002063,
32205
+ 1747873779,
32206
+ 1955562222,
32207
+ 2024104815,
32208
+ 2227730452,
32209
+ 2361852424,
32210
+ 2428436474,
32211
+ 2756734187,
32212
+ 3204031479,
32213
+ 3329325298
32214
+ ]);
32215
+ const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
32216
+ class SHA2_32B extends HashMD {
32217
+ constructor(outputLen, IV) {
32218
+ super(64, outputLen, 8, false);
32219
+ // We cannot use array here since array allows indexing by variable
32220
+ // which means optimizer/compiler cannot use registers.
32221
+ // Numeric initializers matter: starting the fields as `undefined` changes
32222
+ // V8's field representation and makes sha256 3x slower (measured).
32223
+ __publicField(this, "A", 0);
32224
+ __publicField(this, "B", 0);
32225
+ __publicField(this, "C", 0);
32226
+ __publicField(this, "D", 0);
32227
+ __publicField(this, "E", 0);
32228
+ __publicField(this, "F", 0);
32229
+ __publicField(this, "G", 0);
32230
+ __publicField(this, "H", 0);
32231
+ this.A = IV[0] | 0;
32232
+ this.B = IV[1] | 0;
32233
+ this.C = IV[2] | 0;
32234
+ this.D = IV[3] | 0;
32235
+ this.E = IV[4] | 0;
32236
+ this.F = IV[5] | 0;
32237
+ this.G = IV[6] | 0;
32238
+ this.H = IV[7] | 0;
32239
+ }
32240
+ get() {
32241
+ const { A: A10, B, C, D: D10, E: E7, F, G: G10, H } = this;
32242
+ return [A10, B, C, D10, E7, F, G10, H];
32243
+ }
32244
+ // prettier-ignore
32245
+ set(A10, B, C, D10, E7, F, G10, H) {
32246
+ this.A = A10 | 0;
32247
+ this.B = B | 0;
32248
+ this.C = C | 0;
32249
+ this.D = D10 | 0;
32250
+ this.E = E7 | 0;
32251
+ this.F = F | 0;
32252
+ this.G = G10 | 0;
32253
+ this.H = H | 0;
32254
+ }
32255
+ _cloneInto(to2) {
32256
+ (to2 || (to2 = new this.constructor())).set(...this.get());
32257
+ return this._cloneIntoMeta(to2);
32258
+ }
32259
+ process(view, offset2) {
32260
+ for (let i10 = 0; i10 < 16; i10++, offset2 += 4)
32261
+ SHA256_W[i10] = view.getUint32(offset2, false);
32262
+ for (let i10 = 16; i10 < 64; i10++) {
32263
+ const W15 = SHA256_W[i10 - 15];
32264
+ const W22 = SHA256_W[i10 - 2];
32265
+ const s02 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
32266
+ const s12 = rotr(W22, 17) ^ rotr(W22, 19) ^ W22 >>> 10;
32267
+ SHA256_W[i10] = s12 + SHA256_W[i10 - 7] + s02 + SHA256_W[i10 - 16] | 0;
32268
+ }
32269
+ let { A: A10, B, C, D: D10, E: E7, F, G: G10, H } = this;
32270
+ for (let i10 = 0; i10 < 64; i10++) {
32271
+ const sigma12 = rotr(E7, 6) ^ rotr(E7, 11) ^ rotr(E7, 25);
32272
+ const T12 = H + sigma12 + Chi(E7, F, G10) + SHA256_K[i10] + SHA256_W[i10] | 0;
32273
+ const sigma02 = rotr(A10, 2) ^ rotr(A10, 13) ^ rotr(A10, 22);
32274
+ const T22 = sigma02 + Maj(A10, B, C) | 0;
32275
+ H = G10;
32276
+ G10 = F;
32277
+ F = E7;
32278
+ E7 = D10 + T12 | 0;
32279
+ D10 = C;
32280
+ C = B;
32281
+ B = A10;
32282
+ A10 = T12 + T22 | 0;
32283
+ }
32284
+ A10 = A10 + this.A | 0;
32285
+ B = B + this.B | 0;
32286
+ C = C + this.C | 0;
32287
+ D10 = D10 + this.D | 0;
32288
+ E7 = E7 + this.E | 0;
32289
+ F = F + this.F | 0;
32290
+ G10 = G10 + this.G | 0;
32291
+ H = H + this.H | 0;
32292
+ this.set(A10, B, C, D10, E7, F, G10, H);
32293
+ }
32294
+ roundClean() {
32295
+ clean(SHA256_W);
32296
+ }
32297
+ destroy() {
32298
+ this.destroyed = true;
32299
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
32300
+ clean(this.buffer);
32301
+ }
32302
+ }
32303
+ class _SHA256 extends SHA2_32B {
32304
+ constructor() {
32305
+ super(32, SHA256_IV);
32306
+ }
32307
+ }
32308
+ const sha256 = /* @__PURE__ */ createHasher(
32309
+ () => new _SHA256(),
32310
+ /* @__PURE__ */ oidNist(1)
32311
+ );
32106
32312
  const fsModule = lazyModule("fs");
32107
32313
  lazyModule("internal/fs/promises");
32108
32314
  function fsModuleFor(process2) {
@@ -78295,6 +78501,30 @@ Object.defineProperty(globalThis, "__substrateEvalSource", {
78295
78501
  configurable: true,
78296
78502
  value: (source) => typeof source === "string" ? __substrateRewriteDynamicImportsInScript(source) : source
78297
78503
  });
78504
+ function __substratePrepareBody(rawCode, resolvedPath, format2, process2) {
78505
+ let code2 = rawCode;
78506
+ if (code2.startsWith("#!")) {
78507
+ code2 = code2.slice(code2.indexOf("\n") + 1);
78508
+ }
78509
+ code2 = __substrateModuleTypes(code2, resolvedPath, format2, process2);
78510
+ const __commonjs = format2 === "commonjs" || format2 === "commonjs-typescript" ? true : format2 === "module" || format2 === "module-typescript" ? false : resolvedPath.endsWith(".cjs") || resolvedPath.endsWith(".cts");
78511
+ if (!__commonjs) {
78512
+ const lowered = transformEsmToCjs(code2, resolvedPath);
78513
+ code2 = lowered === code2 ? code2 : `${__substrateModuleMarker}"use strict";${lowered}`;
78514
+ } else {
78515
+ code2 = transformDynamicImportsRegex(code2);
78516
+ }
78517
+ return code2;
78518
+ }
78519
+ const PREPARED_MODULES_DIR = "/.tabnode/prepared";
78520
+ const PREPARED_MODULES_FORMAT = "tabnode-prepared-1";
78521
+ function preparedModuleKey(rawCode, resolvedPath) {
78522
+ var _a3;
78523
+ const extension = (_a3 = /\.(js|cjs|mjs)$/u.exec(resolvedPath)) == null ? void 0 : _a3[1];
78524
+ if (!extension) return void 0;
78525
+ const kind = extension === "cjs" ? "cjs" : "js";
78526
+ return bytesToHex(sha256(new TextEncoder().encode(`${PREPARED_MODULES_FORMAT}|${kind}|${rawCode}`)));
78527
+ }
78298
78528
  function transformEsmToCjs(code2, filename) {
78299
78529
  const maybeEsm = __substrateHasEsmSyntax(code2);
78300
78530
  if (!maybeEsm) return __substrateRewriteDynamicImportsInScript(code2);
@@ -79333,6 +79563,14 @@ function createRequire(vfs2, fsShim, process2, currentDir, moduleCache, options,
79333
79563
  }
79334
79564
  const rawCode = source === void 0 || source === null ? defaultSource() : String(source);
79335
79565
  const dirname$1 = resolvedPath.startsWith("data:") ? currentDir : dirname(resolvedPath);
79566
+ if (format2 === void 0 && !transformsTypes(process2) && vfs2.existsSync(PREPARED_MODULES_DIR)) {
79567
+ const key = preparedModuleKey(rawCode, resolvedPath);
79568
+ const prepared = key ? `${PREPARED_MODULES_DIR}/${key}` : void 0;
79569
+ if (prepared && vfs2.existsSync(prepared)) {
79570
+ runModuleBody(module, vfs2.readFileSync(prepared, "utf8"), resolvedPath, dirname$1, true);
79571
+ return module;
79572
+ }
79573
+ }
79336
79574
  runModuleBody(module, prepareModuleCode(rawCode, resolvedPath, format2), resolvedPath, dirname$1);
79337
79575
  return module;
79338
79576
  };
@@ -79340,23 +79578,12 @@ function createRequire(vfs2, fsShim, process2, currentDir, moduleCache, options,
79340
79578
  const codeCacheKey = `${resolvedPath}|${format2 ?? ""}|${transformsTypes(process2) ? "transform-types|" : ""}${simpleHash(rawCode)}`;
79341
79579
  let code2 = processedCodeCache == null ? void 0 : processedCodeCache.get(codeCacheKey);
79342
79580
  if (!code2) {
79343
- code2 = rawCode;
79344
- if (code2.startsWith("#!")) {
79345
- code2 = code2.slice(code2.indexOf("\n") + 1);
79346
- }
79347
- code2 = __substrateModuleTypes(code2, resolvedPath, format2, process2);
79348
- const __commonjs = format2 === "commonjs" || format2 === "commonjs-typescript" ? true : format2 === "module" || format2 === "module-typescript" ? false : resolvedPath.endsWith(".cjs") || resolvedPath.endsWith(".cts");
79349
- if (!__commonjs) {
79350
- const lowered = transformEsmToCjs(code2, resolvedPath);
79351
- code2 = lowered === code2 ? code2 : `${__substrateModuleMarker}"use strict";${lowered}`;
79352
- } else {
79353
- code2 = transformDynamicImportsRegex(code2);
79354
- }
79581
+ code2 = __substratePrepareBody(rawCode, resolvedPath, format2, process2);
79355
79582
  processedCodeCache == null ? void 0 : processedCodeCache.set(codeCacheKey, code2);
79356
79583
  }
79357
79584
  return code2;
79358
79585
  };
79359
- const runModuleBody = (module, prepared, resolvedPath, dirname2) => {
79586
+ const runModuleBody = (module, prepared, resolvedPath, dirname2, scoped = false) => {
79360
79587
  let code2 = prepared;
79361
79588
  const moduleRequire = createRequire(
79362
79589
  vfs2,
@@ -79373,7 +79600,7 @@ function createRequire(vfs2, fsShim, process2, currentDir, moduleCache, options,
79373
79600
  try {
79374
79601
  const importMetaUrl = resolvedPath.startsWith("data:") ? resolvedPath : "file://" + resolvedPath;
79375
79602
  const strictBody = code2.startsWith(__substrateModuleMarker);
79376
- code2 = __substrateScopeGlobalCalls(code2);
79603
+ if (!scoped) code2 = __substrateScopeGlobalCalls(code2);
79377
79604
  const wrappedCode = `(function($exports, $require, $module, $filename, $dirname, $process, $console, $importMeta, $dynamicImport, __substrateGuestGlobal, __substrateGuestConstructor) { var exports = $exports; var require = $require; var module = $module; var __filename = $filename; var __dirname = $dirname; var process = $process; var console = $console; var import_meta = $importMeta; var __dynamicImport = $dynamicImport; var document = void 0, window = void 0, location = void 0, self = void 0; var globalThis = __substrateGuestGlobal($process); var global = globalThis; var Buffer = globalThis.Buffer; var queueMicrotask = globalThis.queueMicrotask, atob = globalThis.atob, btoa = globalThis.btoa, structuredClone = globalThis.structuredClone, setTimeout = globalThis.setTimeout, clearTimeout = globalThis.clearTimeout, setInterval = globalThis.setInterval, clearInterval = globalThis.clearInterval; globalThis.process = $process; global.process = $process; with ({ __proto__: null, get navigator() { return globalThis.navigator; }, set navigator(value) { globalThis.navigator = value; }, get Navigator() { return globalThis.Navigator; }, set Navigator(value) { globalThis.Navigator = value; }, get Promise() { return globalThis.Promise; }, set Promise(value) { globalThis.Promise = value; }, get fetch() { return globalThis.fetch; }, set fetch(value) { globalThis.fetch = value; } }) { return (function() {${code2}
79378
79605
  }).call(${strictBody ? "void 0" : "$module.exports"}); }
79379
79606
  })${__substrateSourceURL(resolvedPath)}`;
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  export { restoreHostGlobals, guestRealmInstalled } from './host-globals';
11
11
  export { VirtualFS } from './virtual-fs';
12
12
  export type { FSNode, MountedTree, Stats, FSWatcher, WatchListener, WatchEventType } from './virtual-fs';
13
- export { Runtime, execute } from './runtime';
13
+ export { Runtime, execute, prepareModuleForImage, preparedModuleKey, PREPARED_MODULES_DIR } from './runtime';
14
14
  export type { Module, RuntimeOptions, RequireFunction } from './runtime';
15
15
  export { createRuntime, WorkerRuntime } from './create-runtime';
16
16
  export type { IRuntime, IExecuteResult, CreateRuntimeOptions, IRuntimeOptions, VFSSnapshot } from './runtime-interface';
@@ -31,6 +31,7 @@ export { utilModule as util } from './node-lib/util-module';
31
31
  export * as npm from './npm';
32
32
  export { PackageManager, install } from './npm';
33
33
  export { ServerBridge, getServerBridge, resetServerBridge } from './server-bridge';
34
+ export { PortBridge, getPortBridge } from './port-bridge';
34
35
  export type { InitServiceWorkerOptions } from './server-bridge';
35
36
  /** What a page's request is answered with, the shape the bridge answers. */
36
37
  export type { ResponseData, LoopbackStreamFlow } from './node-lib/http-bridge';