@volter/tabnode 0.5.47 → 0.5.49

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.
@@ -5425,7 +5425,7 @@ function parse(urlString, parseQueryString = false, slashesDenoteHost = false) {
5425
5425
  hostname: null,
5426
5426
  hash: __hash,
5427
5427
  search: __search,
5428
- query: parseQueryString ? Object.fromEntries(new URLSearchParams(__search || "")) : __search ? __search.slice(1) : null,
5428
+ query: parseQueryString ? Object.fromEntries(new URLSearchParams$1(__search || "")) : __search ? __search.slice(1) : null,
5429
5429
  pathname: __pathname || null,
5430
5430
  path: __pathname + (__search || "") || null,
5431
5431
  href: urlString
@@ -5499,7 +5499,7 @@ function format(urlObject) {
5499
5499
  if (typeof urlObject.query === "string") {
5500
5500
  result += "?" + urlObject.query;
5501
5501
  } else {
5502
- const params = new URLSearchParams();
5502
+ const params = new URLSearchParams$1();
5503
5503
  for (const [key, value] of Object.entries(urlObject.query)) {
5504
5504
  if (Array.isArray(value)) {
5505
5505
  for (const v2 of value) {
@@ -5528,7 +5528,7 @@ function resolve$2(from, to2) {
5528
5528
  }
5529
5529
  }
5530
5530
  const URL$1 = globalThis.URL;
5531
- const URLSearchParams = globalThis.URLSearchParams;
5531
+ const URLSearchParams$1 = globalThis.URLSearchParams;
5532
5532
  function fileURLToPath(url2) {
5533
5533
  const urlObj = typeof url2 === "string" ? new globalThis.URL(url2) : url2;
5534
5534
  if (urlObj.protocol !== "file:") {
@@ -5551,7 +5551,7 @@ var url$1 = {
5551
5551
  format,
5552
5552
  resolve: resolve$2,
5553
5553
  URL: URL$1,
5554
- URLSearchParams,
5554
+ URLSearchParams: URLSearchParams$1,
5555
5555
  URLPattern: URLPattern$1,
5556
5556
  fileURLToPath,
5557
5557
  pathToFileURL
@@ -5560,7 +5560,7 @@ var urlShim = /* @__PURE__ */ Object.freeze({
5560
5560
  __proto__: null,
5561
5561
  URL: URL$1,
5562
5562
  URLPattern: URLPattern$1,
5563
- URLSearchParams,
5563
+ URLSearchParams: URLSearchParams$1,
5564
5564
  default: url$1,
5565
5565
  fileURLToPath,
5566
5566
  format,
@@ -32270,6 +32270,68 @@ function guestPromise(owner) {
32270
32270
  }
32271
32271
  return constructor;
32272
32272
  }
32273
+ const kIsDisturbed = Symbol.for("nodejs.stream.disturbed");
32274
+ function isAsyncIterableBody(body) {
32275
+ if (body === null || typeof body !== "object") return false;
32276
+ if (typeof ReadableStream === "function" && body instanceof ReadableStream) return false;
32277
+ if (typeof Blob === "function" && body instanceof Blob) return false;
32278
+ if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) return false;
32279
+ if (typeof FormData === "function" && body instanceof FormData) return false;
32280
+ if (body instanceof URLSearchParams) return false;
32281
+ return typeof body[Symbol.asyncIterator] === "function";
32282
+ }
32283
+ function refuseDisturbed(body) {
32284
+ const stream = body;
32285
+ const disturbed = stream[kIsDisturbed] !== void 0 ? Boolean(stream[kIsDisturbed]) : Boolean(stream.readableDidRead || stream.readableAborted);
32286
+ if (disturbed || stream.locked === true) throw new TypeError("Response body object should not be disturbed or locked");
32287
+ }
32288
+ function streamFrom(iterable) {
32289
+ let iterator;
32290
+ return new ReadableStream({
32291
+ async start() {
32292
+ iterator = iterable[Symbol.asyncIterator]();
32293
+ },
32294
+ async pull(controller) {
32295
+ for (; ; ) {
32296
+ const { done, value } = await iterator.next();
32297
+ if (done) {
32298
+ controller.close();
32299
+ return;
32300
+ }
32301
+ const bytes2 = Buffer$9.isBuffer(value) ? value : Buffer$9.from(value);
32302
+ if (bytes2.byteLength) {
32303
+ controller.enqueue(new Uint8Array(bytes2));
32304
+ return;
32305
+ }
32306
+ }
32307
+ },
32308
+ async cancel() {
32309
+ var _a3;
32310
+ await ((_a3 = iterator == null ? void 0 : iterator.return) == null ? void 0 : _a3.call(iterator));
32311
+ }
32312
+ }, { highWaterMark: 0 });
32313
+ }
32314
+ const REQUEST_INIT_MEMBERS = ["method", "headers", "referrer", "referrerPolicy", "mode", "credentials", "cache", "redirect", "integrity", "keepalive", "signal", "window", "duplex", "priority"];
32315
+ function withNodeRequestBody(init) {
32316
+ if (!init) return init;
32317
+ const body = init.body;
32318
+ if (!isAsyncIterableBody(body)) return init;
32319
+ refuseDisturbed(body);
32320
+ const copy2 = {};
32321
+ for (const member of Object.keys(init)) if (member !== "body") copy2[member] = init[member];
32322
+ for (const member of REQUEST_INIT_MEMBERS) {
32323
+ if (member in copy2) continue;
32324
+ const value = init[member];
32325
+ if (value !== void 0) copy2[member] = value;
32326
+ }
32327
+ copy2.body = streamFrom(body);
32328
+ return copy2;
32329
+ }
32330
+ function nodeResponseBody(body) {
32331
+ if (!isAsyncIterableBody(body)) return body;
32332
+ refuseDisturbed(body);
32333
+ return streamFrom(body);
32334
+ }
32273
32335
  const staticRequestBodies = /* @__PURE__ */ new WeakSet();
32274
32336
  function rememberRequestBodySource(request, input, init) {
32275
32337
  if (!request.body) return;
@@ -32279,9 +32341,132 @@ function rememberRequestBodySource(request, input, init) {
32279
32341
  }
32280
32342
  function guestFetch(process2, fallback) {
32281
32343
  return function fetch2(input, init) {
32344
+ try {
32345
+ init = withNodeRequestBody(init);
32346
+ } catch (error) {
32347
+ return Promise.reject(error);
32348
+ }
32282
32349
  return fallback.call(globalThis, input, init);
32283
32350
  };
32284
32351
  }
32352
+ const INSTALLED = Symbol.for("tabnode.response.keepsSetCookie");
32353
+ function withCookies(own, given) {
32354
+ const headers = new Headers(own);
32355
+ if (!given) return headers;
32356
+ const cookies = [];
32357
+ if (typeof given.getSetCookie === "function") cookies.push(...given.getSetCookie());
32358
+ else given.forEach((value, name) => {
32359
+ if (name === "set-cookie") cookies.push(value);
32360
+ });
32361
+ if (cookies.length) {
32362
+ headers.delete("set-cookie");
32363
+ for (const cookie of cookies) headers.append("set-cookie", cookie);
32364
+ }
32365
+ const cookie2 = given.get("set-cookie2");
32366
+ if (cookie2 !== null) headers.set("set-cookie2", cookie2);
32367
+ return headers;
32368
+ }
32369
+ function givenHeaders(init) {
32370
+ const headers = init == null ? void 0 : init.headers;
32371
+ return headers === void 0 || headers === null ? void 0 : new Headers(headers);
32372
+ }
32373
+ function withHeaders(init, headers) {
32374
+ const status = init == null ? void 0 : init.status;
32375
+ const statusText = init == null ? void 0 : init.statusText;
32376
+ return {
32377
+ headers,
32378
+ ...status === void 0 ? {} : { status },
32379
+ ...statusText === void 0 ? {} : { statusText }
32380
+ };
32381
+ }
32382
+ function installNodeResponse(target) {
32383
+ var _a3;
32384
+ const Native = target.Response;
32385
+ if (typeof Native !== "function" || Native[INSTALLED]) return;
32386
+ const proto = Native.prototype;
32387
+ let nativeHeaders;
32388
+ for (let at3 = proto; at3 && !nativeHeaders; at3 = Object.getPrototypeOf(at3)) nativeHeaders = (_a3 = Object.getOwnPropertyDescriptor(at3, "headers")) == null ? void 0 : _a3.get;
32389
+ const nativeFormData = proto.formData;
32390
+ const nativeBlob = proto.blob;
32391
+ const nativeArrayBuffer = proto.arrayBuffer;
32392
+ const nativeClone = proto.clone;
32393
+ if (!nativeHeaders) return;
32394
+ const kept = /* @__PURE__ */ new WeakMap();
32395
+ const NodeResponse = function Response2(body, init) {
32396
+ if (!new.target) throw new TypeError("Class constructor Response cannot be invoked without 'new'");
32397
+ const given = givenHeaders(init);
32398
+ const response = Reflect.construct(Native, [nodeResponseBody(body), given ? withHeaders(init, given) : init], new.target === NodeResponse ? Native : new.target);
32399
+ kept.set(response, withCookies(nativeHeaders.call(response), given));
32400
+ return response;
32401
+ };
32402
+ NodeResponse.prototype = proto;
32403
+ Object.defineProperty(NodeResponse, "length", { value: 0, configurable: true });
32404
+ Object.defineProperty(NodeResponse, INSTALLED, { value: true });
32405
+ Object.setPrototypeOf(NodeResponse, Object.getPrototypeOf(Native));
32406
+ Object.defineProperty(NodeResponse, "json", {
32407
+ value: function json(data2, init) {
32408
+ const given = givenHeaders(init);
32409
+ const response = Native.json(data2, given ? withHeaders(init, given) : init);
32410
+ kept.set(response, withCookies(nativeHeaders.call(response), given));
32411
+ return response;
32412
+ },
32413
+ writable: true,
32414
+ configurable: true
32415
+ });
32416
+ Object.defineProperty(NodeResponse, "redirect", { value: function redirect(url2, status) {
32417
+ return Native.redirect(url2, status);
32418
+ }, writable: true, configurable: true });
32419
+ Object.defineProperty(NodeResponse, "error", { value: function error() {
32420
+ return Native.error();
32421
+ }, writable: true, configurable: true });
32422
+ defineOnHost(proto, "headers", {
32423
+ get() {
32424
+ return kept.get(this) ?? nativeHeaders.call(this);
32425
+ },
32426
+ enumerable: true,
32427
+ configurable: true
32428
+ });
32429
+ defineOnHost(proto, "constructor", { value: NodeResponse, writable: true, enumerable: false, configurable: true });
32430
+ defineOnHost(proto, "clone", {
32431
+ value: function clone() {
32432
+ const copy2 = nativeClone.call(this);
32433
+ const headers = kept.get(this);
32434
+ if (headers) kept.set(copy2, new Headers(headers));
32435
+ return copy2;
32436
+ },
32437
+ writable: true,
32438
+ enumerable: true,
32439
+ configurable: true
32440
+ });
32441
+ const changedType = (response) => {
32442
+ const headers = kept.get(response);
32443
+ if (!headers) return void 0;
32444
+ const current3 = headers.get("content-type");
32445
+ return current3 === nativeHeaders.call(response).get("content-type") ? void 0 : current3;
32446
+ };
32447
+ defineOnHost(proto, "formData", {
32448
+ value: async function formData() {
32449
+ const type2 = changedType(this);
32450
+ if (type2 === void 0) return nativeFormData.call(this);
32451
+ const bytes2 = await nativeArrayBuffer.call(this);
32452
+ return nativeFormData.call(Reflect.construct(Native, [bytes2, type2 === null ? {} : { headers: { "content-type": type2 } }]));
32453
+ },
32454
+ writable: true,
32455
+ enumerable: true,
32456
+ configurable: true
32457
+ });
32458
+ defineOnHost(proto, "blob", {
32459
+ value: async function blob() {
32460
+ const type2 = changedType(this);
32461
+ if (type2 === void 0) return nativeBlob.call(this);
32462
+ return new Blob([await nativeArrayBuffer.call(this)], type2 === null ? {} : { type: type2 });
32463
+ },
32464
+ writable: true,
32465
+ enumerable: true,
32466
+ configurable: true
32467
+ });
32468
+ takeFromHost(target, "Response", NodeResponse);
32469
+ }
32285
32470
  function simpleHash(str) {
32286
32471
  let hash2 = 0;
32287
32472
  for (let i10 = 0; i10 < str.length; i10++) {
@@ -74097,6 +74282,63 @@ function installShellJobs(bash, host) {
74097
74282
  if (shell.jobs.size === 0) shells$1.delete(id2);
74098
74283
  return { stdout: held.stdout, stderr: held.stderr + stderr, exitCode: status };
74099
74284
  }));
74285
+ for (const shell of ["sh", "bash"]) {
74286
+ bash.registerCommand(uA(shell, async (args, ctx) => {
74287
+ var _a3;
74288
+ const exec = ctx.exec;
74289
+ if (!exec) return { stdout: "", stderr: `bash: ${shell}: needs a shell that can run a script
74290
+ `, exitCode: 1 };
74291
+ let script;
74292
+ let zero2;
74293
+ let positional;
74294
+ let sourced;
74295
+ let at3 = 0;
74296
+ while (at3 < args.length && /^[-+][a-bd-zA-Z]+$/u.test(args[at3])) at3++;
74297
+ args = args.slice(at3);
74298
+ if (args[0] === "-c" && args.length >= 2) {
74299
+ script = args[1];
74300
+ zero2 = args[2] ?? shell;
74301
+ positional = args.slice(3);
74302
+ } else if (args.length === 0) {
74303
+ if (!((_a3 = ctx.stdin) == null ? void 0 : _a3.trim())) return { stdout: "", stderr: "", exitCode: 0 };
74304
+ script = ctx.stdin;
74305
+ zero2 = shell;
74306
+ positional = [];
74307
+ } else {
74308
+ const path2 = ctx.fs.resolvePath(ctx.cwd, args[0]);
74309
+ try {
74310
+ script = String(await ctx.fs.readFile(path2));
74311
+ } catch {
74312
+ return { stdout: "", stderr: `${shell}: ${args[0]}: No such file or directory
74313
+ `, exitCode: 127 };
74314
+ }
74315
+ zero2 = args[0];
74316
+ positional = args.slice(1);
74317
+ sourced = path2;
74318
+ }
74319
+ if (script.startsWith("#!")) {
74320
+ const newline = script.indexOf("\n");
74321
+ if (newline !== -1) script = script.slice(newline + 1);
74322
+ }
74323
+ const env = { ...ctx.exportedEnv ?? {}, "0": zero2, "#": String(positional.length), "@": positional.join(" "), "*": positional.join(" ") };
74324
+ positional.forEach((word, index2) => {
74325
+ env[String(index2 + 1)] = word;
74326
+ });
74327
+ const token = ctx.env.get(PROCESS_TOKEN_ENV);
74328
+ if (token) env[PROCESS_TOKEN_ENV] = token;
74329
+ if (sourced !== void 0) script = `. ${sourced.replace(/'/gu, "'\\''").replace(/^(.*)$/su, "'$1'")}`;
74330
+ const result = await exec(script, { env, cwd: ctx.cwd, stdin: ctx.stdin, signal: ctx.signal });
74331
+ return { stdout: result.stdout ?? "", stderr: result.stderr ?? "", exitCode: result.exitCode ?? 0 };
74332
+ }));
74333
+ }
74334
+ bash.registerCommand(uA("exec", async (args, ctx) => {
74335
+ if (args.length === 0) return { stdout: "", stderr: "", exitCode: 0 };
74336
+ if (!ctx.exec) return { stdout: "", stderr: "bash: exec: needs a shell that can run a line\n", exitCode: 1 };
74337
+ const line = args.map((word) => /^[A-Za-z0-9_./:=@%+,-]+$/u.test(word) ? word : `'${word.replace(/'/gu, "'\\''")}'`).join(" ");
74338
+ const env = Object.fromEntries(ctx.env);
74339
+ const result = await ctx.exec(line, { env, cwd: ctx.cwd, replaceEnv: true });
74340
+ return { stdout: result.stdout ?? "", stderr: result.stderr ?? "", exitCode: result.exitCode ?? 0 };
74341
+ }));
74100
74342
  bash.registerCommand(uA("kill", async (args) => {
74101
74343
  let signal = "SIGTERM";
74102
74344
  let index2 = 0;
@@ -74278,6 +74520,18 @@ function registerRunStreams(token, streams2) {
74278
74520
  }
74279
74521
  function releaseRunStreams(token) {
74280
74522
  _runStreams.delete(token);
74523
+ shellRuns.delete(token);
74524
+ hostedNodes.delete(token);
74525
+ }
74526
+ const shellRuns = /* @__PURE__ */ new Set();
74527
+ const hostedNodes = /* @__PURE__ */ new Set();
74528
+ function nestedNodeToken(parentToken, args, cwd) {
74529
+ var _a3;
74530
+ const token = `child-${__nextChildRun++}`;
74531
+ setRunPid(token, mintPid(), ((_a3 = runPid(parentToken)) == null ? void 0 : _a3.pid) ?? 0, { argv: ["node", ...args], ...cwd ? { cwd } : {} });
74532
+ const parentStreams = runStreamsFor(parentToken);
74533
+ if (parentStreams) registerRunStreams(token, parentStreams);
74534
+ return token;
74281
74535
  }
74282
74536
  function runStreamsFor(token) {
74283
74537
  return _runStreams.get(token);
@@ -74346,19 +74600,26 @@ function initChildProcess(vfs2) {
74346
74600
  if (!tree2) {
74347
74601
  return { stdout: "", stderr: "VFS not initialized\n", exitCode: 1 };
74348
74602
  }
74349
- const runToken = runTokenOf(ctx);
74603
+ const parentToken = runTokenOf(ctx);
74604
+ const nested = parentToken !== null && (shellRuns.has(parentToken) || hostedNodes.has(parentToken));
74605
+ const runToken = nested ? nestedNodeToken(parentToken, args, ctx.cwd) : parentToken;
74350
74606
  const streams2 = runToken === null ? void 0 : runStreamsFor(runToken);
74351
74607
  const processHost = nodeProcessHostFor();
74352
74608
  if (processHost && runToken !== null) {
74353
- return runHostedNode(processHost, {
74354
- token: runToken,
74355
- argv: [...args],
74356
- cwd: ctx.cwd,
74357
- filesystem: tree2,
74358
- env: guestEnvironmentOf(ctx),
74359
- ...typeof ctx.stdin === "string" ? { stdin: ctx.stdin } : {},
74360
- ...streams2 ? { streams: streams2 } : {}
74361
- });
74609
+ if (!nested) hostedNodes.add(runToken);
74610
+ try {
74611
+ return await runHostedNode(processHost, {
74612
+ token: runToken,
74613
+ argv: [...args],
74614
+ cwd: ctx.cwd,
74615
+ filesystem: tree2,
74616
+ env: guestEnvironmentOf(ctx),
74617
+ ...typeof ctx.stdin === "string" ? { stdin: ctx.stdin } : {},
74618
+ ...streams2 ? { streams: streams2 } : {}
74619
+ });
74620
+ } finally {
74621
+ if (nested) releaseRunStreams(runToken);
74622
+ }
74362
74623
  }
74363
74624
  const execArgv = [];
74364
74625
  let first = 0;
@@ -75244,6 +75505,7 @@ function existsInTree(path2) {
75244
75505
  return false;
75245
75506
  }
75246
75507
  }
75508
+ const SHELL_PROGRAMS = /* @__PURE__ */ new Set(["sh", "bash", "dash", "/bin/sh", "/bin/bash", "/usr/bin/sh", "/usr/bin/bash"]);
75247
75509
  function engineProgramFor(file, cwd) {
75248
75510
  const name = __substrateProgramName(file);
75249
75511
  if (!name.includes("/")) return name;
@@ -75290,6 +75552,7 @@ function startChildRun(request) {
75290
75552
  const controller = new AbortController();
75291
75553
  const pendingStdin = [];
75292
75554
  const admittedNode = nodeProcessHostInstalled();
75555
+ shellRuns.add(token);
75293
75556
  const hostTerminal = request.terminal !== void 0 && hostExecutor() !== null && !admittedNode;
75294
75557
  let wakeInput;
75295
75558
  let liveInput = false;
@@ -75388,7 +75651,8 @@ function startChildRun(request) {
75388
75651
  const begin = () => {
75389
75652
  if (started || finished) return;
75390
75653
  started = true;
75391
- const engineFirst = !hostTerminal && programExists(request.file, request.cwd, request.env);
75654
+ const shellChild = SHELL_PROGRAMS.has(engineProgramFor(request.file, request.cwd)) && hostExecutor() !== null;
75655
+ const engineFirst = !hostTerminal && !shellChild && programExists(request.file, request.cwd, request.env);
75392
75656
  liveInput = !hostTerminal && !admittedNode && request.stdinIsPipe && !engineFirst;
75393
75657
  if (liveInput) {
75394
75658
  pendingStdin.unshift(...initialStdin);
@@ -80438,6 +80702,7 @@ forGuestRealm(() => {
80438
80702
  const kept = /* @__PURE__ */ new WeakMap();
80439
80703
  class NodeRequest extends Native {
80440
80704
  constructor(input, init) {
80705
+ init = withNodeRequestBody(init);
80441
80706
  super(input, init);
80442
80707
  rememberRequestBodySource(this, input, init);
80443
80708
  const asked = new Headers((init == null ? void 0 : init.headers) ?? (input instanceof Native ? input.headers : void 0));
@@ -80461,6 +80726,9 @@ forGuestRealm(() => {
80461
80726
  takeFromHost(globalThis, "Request", NodeRequest);
80462
80727
  }
80463
80728
  });
80729
+ forGuestRealm(() => {
80730
+ installNodeResponse(globalThis);
80731
+ });
80464
80732
  forGuestRealm(() => {
80465
80733
  const kIsClosedPromise = Symbol.for("nodejs.webstream.isClosedPromise");
80466
80734
  const Native = globalThis.ReadableStream;
@@ -1,4 +1,3 @@
1
- /** Host Fetch I/O uses the same process-owned liveness registry as sockets. */
2
1
  import type { Process } from './shims/process';
3
2
  export interface FetchActivity {
4
3
  /** One pending transport operation; the returned release is idempotent. */