@volter/tabnode 0.5.7 → 0.5.8

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.
@@ -9324,7 +9324,16 @@ const osBinding = {
9324
9324
  /** Node's `os.type()`, `release()` and `version()`, in that order. */
9325
9325
  getOSInformation: () => [type$1(), release(), version$2()],
9326
9326
  getHostname: () => hostname(),
9327
- getHomeDirectory: () => homedir(),
9327
+ /**
9328
+ * Node's `os.homedir()` is libuv's: `HOME` when the environment sets it,
9329
+ * the account's directory otherwise. `userInfo().homedir` stays the
9330
+ * account's, as it is in Node.
9331
+ */
9332
+ getHomeDirectory: () => {
9333
+ var _a3, _b3;
9334
+ const home = (_b3 = (_a3 = globalThis.process) == null ? void 0 : _a3.env) == null ? void 0 : _b3.HOME;
9335
+ return home && home.length > 0 ? home : homedir();
9336
+ },
9328
9337
  getUptime: () => uptime(),
9329
9338
  getTotalMem: () => totalmem(),
9330
9339
  getFreeMem: () => freemem(),
@@ -73926,7 +73935,10 @@ function __substrateScopeGlobalCalls(code2) {
73926
73935
  }
73927
73936
  const positions = [];
73928
73937
  walkAst(ast, (node) => {
73929
- if (node.type === "NewExpression" && node.callee.type === "Identifier") positions.push([node.callee.start, node.callee.end, "(__substrateGuestConstructor(" + code2.slice(node.callee.start, node.callee.end) + ",$process))"]);
73938
+ if (node.type === "NewExpression" && node.callee.type === "Identifier") {
73939
+ const callee = code2.slice(node.callee.start, node.callee.end);
73940
+ positions.push([node.callee.start, node.callee.end, "(typeof __substrateGuestConstructor==='function'?__substrateGuestConstructor(" + callee + ",$process):" + callee + ")"]);
73941
+ }
73930
73942
  const called = node.type === "CallExpression" ? node.callee : node.type === "TaggedTemplateExpression" ? node.tag : void 0;
73931
73943
  if ((called == null ? void 0 : called.type) === "Identifier" && (called.name === "fetch" || called.name === "Promise")) positions.push([called.start, called.end, "(0," + code2.slice(called.start, called.end) + ")"]);
73932
73944
  });
package/dist/index.mjs CHANGED
@@ -9487,7 +9487,16 @@ const osBinding = {
9487
9487
  /** Node's `os.type()`, `release()` and `version()`, in that order. */
9488
9488
  getOSInformation: () => [type$1(), release(), version$2()],
9489
9489
  getHostname: () => hostname(),
9490
- getHomeDirectory: () => homedir(),
9490
+ /**
9491
+ * Node's `os.homedir()` is libuv's: `HOME` when the environment sets it,
9492
+ * the account's directory otherwise. `userInfo().homedir` stays the
9493
+ * account's, as it is in Node.
9494
+ */
9495
+ getHomeDirectory: () => {
9496
+ var _a2, _b2;
9497
+ const home = (_b2 = (_a2 = globalThis.process) == null ? void 0 : _a2.env) == null ? void 0 : _b2.HOME;
9498
+ return home && home.length > 0 ? home : homedir();
9499
+ },
9491
9500
  getUptime: () => uptime(),
9492
9501
  getTotalMem: () => totalmem(),
9493
9502
  getFreeMem: () => freemem(),
@@ -33619,7 +33628,10 @@ function __substrateScopeGlobalCalls(code2) {
33619
33628
  }
33620
33629
  const positions = [];
33621
33630
  walkAst(ast, (node) => {
33622
- if (node.type === "NewExpression" && node.callee.type === "Identifier") positions.push([node.callee.start, node.callee.end, "(__substrateGuestConstructor(" + code2.slice(node.callee.start, node.callee.end) + ",$process))"]);
33631
+ if (node.type === "NewExpression" && node.callee.type === "Identifier") {
33632
+ const callee = code2.slice(node.callee.start, node.callee.end);
33633
+ positions.push([node.callee.start, node.callee.end, "(typeof __substrateGuestConstructor==='function'?__substrateGuestConstructor(" + callee + ",$process):" + callee + ")"]);
33634
+ }
33623
33635
  const called = node.type === "CallExpression" ? node.callee : node.type === "TaggedTemplateExpression" ? node.tag : void 0;
33624
33636
  if ((called == null ? void 0 : called.type) === "Identifier" && (called.name === "fetch" || called.name === "Promise")) positions.push([called.start, called.end, "(0," + code2.slice(called.start, called.end) + ")"]);
33625
33637
  });
@@ -35683,7 +35695,7 @@ class WorkerRuntime {
35683
35695
  this.worker = new Worker(
35684
35696
  new URL(
35685
35697
  /* @vite-ignore */
35686
- "/assets/runtime-worker-CZQ5Vxoj.js",
35698
+ "/assets/runtime-worker-Cl9uKRen.js",
35687
35699
  import.meta.url
35688
35700
  ),
35689
35701
  { type: "module" }
@@ -38150,7 +38162,7 @@ class NativeStreamScope {
38150
38162
  const handle = entry.handle;
38151
38163
  switch (operation.operation) {
38152
38164
  case "duplicate": {
38153
- if (!handle.peer || handle.listening) return { status: UV_ENOTSUP };
38165
+ if (handle.listening) return { status: UV_ENOTSUP };
38154
38166
  if (this.entries.size >= this.limits.maxHandles) return { status: UV_EMFILE };
38155
38167
  const copy2 = handle.duplicate();
38156
38168
  const descriptor = this.claim(copy2);
@@ -38310,7 +38322,7 @@ class NativeStreamScope {
38310
38322
  if (this.entries.size >= this.limits.maxHandles) return { status: UV_EMFILE };
38311
38323
  const handle = (_a2 = source.entry(id)) == null ? void 0 : _a2.handle;
38312
38324
  if (!handle) return { status: UV_EBADF };
38313
- if (handle.listening || !handle.peer) return { status: UV_ENOTSUP };
38325
+ if (handle.listening) return { status: UV_ENOTSUP };
38314
38326
  const copy2 = handle.duplicate();
38315
38327
  const descriptor = this.claim(copy2);
38316
38328
  if (!descriptor) {
@@ -3,6 +3,11 @@ export declare const osBinding: {
3
3
  /** Node's `os.type()`, `release()` and `version()`, in that order. */
4
4
  getOSInformation: () => string[];
5
5
  getHostname: () => string;
6
+ /**
7
+ * Node's `os.homedir()` is libuv's: `HOME` when the environment sets it,
8
+ * the account's directory otherwise. `userInfo().homedir` stays the
9
+ * account's, as it is in Node.
10
+ */
6
11
  getHomeDirectory: () => string;
7
12
  getUptime: () => number;
8
13
  getTotalMem: () => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/tabnode",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "description": "Node's own library, in a browser tab.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -142,7 +142,9 @@ export class NativeStreamScope {
142
142
  const handle = entry.handle;
143
143
  switch (operation.operation) {
144
144
  case 'duplicate': {
145
- if (!handle.peer || handle.listening) return { status: UV_ENOTSUP };
145
+ // A connection is duplicated whether or not its other end is still
146
+ // there (the copy reads its EOF); a listening server is not one.
147
+ if (handle.listening) return { status: UV_ENOTSUP };
146
148
  if (this.entries.size >= this.limits.maxHandles) return { status: UV_EMFILE };
147
149
  const copy = handle.duplicate();
148
150
  const descriptor = this.claim(copy);
@@ -289,7 +291,7 @@ export class NativeStreamScope {
289
291
  if (this.entries.size >= this.limits.maxHandles) return { status: UV_EMFILE };
290
292
  const handle = source.entry(id)?.handle;
291
293
  if (!handle) return { status: UV_EBADF };
292
- if (handle.listening || !handle.peer) return { status: UV_ENOTSUP };
294
+ if (handle.listening) return { status: UV_ENOTSUP };
293
295
  const copy = handle.duplicate();
294
296
  const descriptor = this.claim(copy);
295
297
  if (!descriptor) { copy.close(); return { status: UV_EMFILE }; }
@@ -81,7 +81,15 @@ export const osBinding = {
81
81
  /** Node's `os.type()`, `release()` and `version()`, in that order. */
82
82
  getOSInformation: (): string[] => [osShim.type(), osShim.release(), osShim.version()],
83
83
  getHostname: (): string => osShim.hostname(),
84
- getHomeDirectory: (): string => osShim.homedir(),
84
+ /**
85
+ * Node's `os.homedir()` is libuv's: `HOME` when the environment sets it,
86
+ * the account's directory otherwise. `userInfo().homedir` stays the
87
+ * account's, as it is in Node.
88
+ */
89
+ getHomeDirectory: (): string => {
90
+ const home = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.HOME;
91
+ return home && home.length > 0 ? home : osShim.homedir();
92
+ },
85
93
  getUptime: (): number => osShim.uptime(),
86
94
  getTotalMem: (): number => osShim.totalmem(),
87
95
  getFreeMem: (): number => osShim.freemem(),
package/src/runtime.ts CHANGED
@@ -142,7 +142,13 @@ function __substrateScopeGlobalCalls(code: string): string {
142
142
  catch { return code; }
143
143
  const positions: Array<[number, number, string]> = [];
144
144
  walkAst(ast, node => {
145
- if (node.type === "NewExpression" && node.callee.type === "Identifier") positions.push([node.callee.start, node.callee.end, "(__substrateGuestConstructor(" + code.slice(node.callee.start, node.callee.end) + ",$process))"]);
145
+ // A function's source is also data: a program sends `String(fn)` to be
146
+ // run elsewhere (a browser page, a worker), where the module wrapper's
147
+ // names do not exist. The rewrite is the original `new` there.
148
+ if (node.type === "NewExpression" && node.callee.type === "Identifier") {
149
+ const callee = code.slice(node.callee.start, node.callee.end);
150
+ positions.push([node.callee.start, node.callee.end, "(typeof __substrateGuestConstructor==='function'?__substrateGuestConstructor(" + callee + ",$process):" + callee + ")"]);
151
+ }
146
152
  // The narrow with-scope below keeps global replacements dynamic.
147
153
  // Remove its object receiver for ordinary calls (including local
148
154
  // bindings, whose bare-call receiver was already undefined).