@volter/tabnode 0.2.14-volter.88

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.
Files changed (429) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +78 -0
  3. package/THIRD-PARTY-NOTICES.md +12 -0
  4. package/dist/__sw__.js +526 -0
  5. package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
  6. package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
  7. package/dist/code-transforms.d.ts +21 -0
  8. package/dist/code-transforms.d.ts.map +1 -0
  9. package/dist/config/cdn.d.ts +12 -0
  10. package/dist/config/cdn.d.ts.map +1 -0
  11. package/dist/create-runtime.d.ts +22 -0
  12. package/dist/create-runtime.d.ts.map +1 -0
  13. package/dist/host-globals.d.ts +62 -0
  14. package/dist/host-globals.d.ts.map +1 -0
  15. package/dist/index.cjs +36021 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +127 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.mjs +36020 -0
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/node-internals.d.ts +68 -0
  22. package/dist/node-internals.d.ts.map +1 -0
  23. package/dist/node-lib/binding/blob.d.ts +12 -0
  24. package/dist/node-lib/binding/blob.d.ts.map +1 -0
  25. package/dist/node-lib/binding/buffer.d.ts +144 -0
  26. package/dist/node-lib/binding/buffer.d.ts.map +1 -0
  27. package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
  28. package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
  29. package/dist/node-lib/binding/fds.d.ts +30 -0
  30. package/dist/node-lib/binding/fds.d.ts.map +1 -0
  31. package/dist/node-lib/binding/fs.d.ts +157 -0
  32. package/dist/node-lib/binding/fs.d.ts.map +1 -0
  33. package/dist/node-lib/binding/handles.d.ts +81 -0
  34. package/dist/node-lib/binding/handles.d.ts.map +1 -0
  35. package/dist/node-lib/binding/http_parser.d.ts +122 -0
  36. package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
  37. package/dist/node-lib/binding/index.d.ts +3 -0
  38. package/dist/node-lib/binding/index.d.ts.map +1 -0
  39. package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
  40. package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
  41. package/dist/node-lib/binding/misc.d.ts +123 -0
  42. package/dist/node-lib/binding/misc.d.ts.map +1 -0
  43. package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
  44. package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
  45. package/dist/node-lib/binding/process_wrap.d.ts +173 -0
  46. package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
  47. package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
  48. package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
  49. package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
  50. package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
  51. package/dist/node-lib/binding/stubs.d.ts +23 -0
  52. package/dist/node-lib/binding/stubs.d.ts.map +1 -0
  53. package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
  54. package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
  55. package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
  56. package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
  57. package/dist/node-lib/binding/util.d.ts +126 -0
  58. package/dist/node-lib/binding/util.d.ts.map +1 -0
  59. package/dist/node-lib/binding/uv.d.ts +32 -0
  60. package/dist/node-lib/binding/uv.d.ts.map +1 -0
  61. package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
  62. package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
  63. package/dist/node-lib/binding/zlib.d.ts +38 -0
  64. package/dist/node-lib/binding/zlib.d.ts.map +1 -0
  65. package/dist/node-lib/buffer-module.d.ts +51 -0
  66. package/dist/node-lib/buffer-module.d.ts.map +1 -0
  67. package/dist/node-lib/child-process-module.d.ts +26 -0
  68. package/dist/node-lib/child-process-module.d.ts.map +1 -0
  69. package/dist/node-lib/events-module.d.ts +58 -0
  70. package/dist/node-lib/events-module.d.ts.map +1 -0
  71. package/dist/node-lib/fs-module.d.ts +5 -0
  72. package/dist/node-lib/fs-module.d.ts.map +1 -0
  73. package/dist/node-lib/http-bridge.d.ts +43 -0
  74. package/dist/node-lib/http-bridge.d.ts.map +1 -0
  75. package/dist/node-lib/http-module.d.ts +35 -0
  76. package/dist/node-lib/http-module.d.ts.map +1 -0
  77. package/dist/node-lib/internals/addresses.d.ts +40 -0
  78. package/dist/node-lib/internals/addresses.d.ts.map +1 -0
  79. package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
  80. package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
  81. package/dist/node-lib/internals/child-process.d.ts +27 -0
  82. package/dist/node-lib/internals/child-process.d.ts.map +1 -0
  83. package/dist/node-lib/internals/events-util.d.ts +83 -0
  84. package/dist/node-lib/internals/events-util.d.ts.map +1 -0
  85. package/dist/node-lib/internals/index.d.ts +2 -0
  86. package/dist/node-lib/internals/index.d.ts.map +1 -0
  87. package/dist/node-lib/internals/modules.d.ts +67 -0
  88. package/dist/node-lib/internals/modules.d.ts.map +1 -0
  89. package/dist/node-lib/internals/readline-access.d.ts +2 -0
  90. package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
  91. package/dist/node-lib/internals/runtime.d.ts +150 -0
  92. package/dist/node-lib/internals/runtime.d.ts.map +1 -0
  93. package/dist/node-lib/internals/util.d.ts +33 -0
  94. package/dist/node-lib/internals/util.d.ts.map +1 -0
  95. package/dist/node-lib/lazy.d.ts +31 -0
  96. package/dist/node-lib/lazy.d.ts.map +1 -0
  97. package/dist/node-lib/load.d.ts +27 -0
  98. package/dist/node-lib/load.d.ts.map +1 -0
  99. package/dist/node-lib/module-hooks.d.ts +89 -0
  100. package/dist/node-lib/module-hooks.d.ts.map +1 -0
  101. package/dist/node-lib/net-module.d.ts +181 -0
  102. package/dist/node-lib/net-module.d.ts.map +1 -0
  103. package/dist/node-lib/node-versions.d.ts +27 -0
  104. package/dist/node-lib/node-versions.d.ts.map +1 -0
  105. package/dist/node-lib/public-modules.d.ts +2 -0
  106. package/dist/node-lib/public-modules.d.ts.map +1 -0
  107. package/dist/node-lib/require-hook.d.ts +15 -0
  108. package/dist/node-lib/require-hook.d.ts.map +1 -0
  109. package/dist/node-lib/small-modules.d.ts +16 -0
  110. package/dist/node-lib/small-modules.d.ts.map +1 -0
  111. package/dist/node-lib/sources.d.ts +4 -0
  112. package/dist/node-lib/sources.d.ts.map +1 -0
  113. package/dist/node-lib/stream-module.d.ts +77 -0
  114. package/dist/node-lib/stream-module.d.ts.map +1 -0
  115. package/dist/node-lib/timers.d.ts +19 -0
  116. package/dist/node-lib/timers.d.ts.map +1 -0
  117. package/dist/node-lib/util-module.d.ts +76 -0
  118. package/dist/node-lib/util-module.d.ts.map +1 -0
  119. package/dist/node-resolution.d.ts +50 -0
  120. package/dist/node-resolution.d.ts.map +1 -0
  121. package/dist/node-resolver.d.ts +7 -0
  122. package/dist/node-resolver.d.ts.map +1 -0
  123. package/dist/npm/index.d.ts +73 -0
  124. package/dist/npm/index.d.ts.map +1 -0
  125. package/dist/npm/registry.d.ts +111 -0
  126. package/dist/npm/registry.d.ts.map +1 -0
  127. package/dist/npm/resolver.d.ts +79 -0
  128. package/dist/npm/resolver.d.ts.map +1 -0
  129. package/dist/npm/tarball.d.ts +28 -0
  130. package/dist/npm/tarball.d.ts.map +1 -0
  131. package/dist/process-tokens.d.ts +77 -0
  132. package/dist/process-tokens.d.ts.map +1 -0
  133. package/dist/punycode-source.d.ts +3 -0
  134. package/dist/punycode-source.d.ts.map +1 -0
  135. package/dist/runtime-interface.d.ts +74 -0
  136. package/dist/runtime-interface.d.ts.map +1 -0
  137. package/dist/runtime.d.ts +144 -0
  138. package/dist/runtime.d.ts.map +1 -0
  139. package/dist/server-bridge.d.ts +147 -0
  140. package/dist/server-bridge.d.ts.map +1 -0
  141. package/dist/shims/async_hooks.d.ts +50 -0
  142. package/dist/shims/async_hooks.d.ts.map +1 -0
  143. package/dist/shims/child_process.d.ts +104 -0
  144. package/dist/shims/child_process.d.ts.map +1 -0
  145. package/dist/shims/cluster.d.ts +52 -0
  146. package/dist/shims/cluster.d.ts.map +1 -0
  147. package/dist/shims/command-line.d.ts +43 -0
  148. package/dist/shims/command-line.d.ts.map +1 -0
  149. package/dist/shims/constants.d.ts +222 -0
  150. package/dist/shims/constants.d.ts.map +1 -0
  151. package/dist/shims/crypto-constants.d.ts +12 -0
  152. package/dist/shims/crypto-constants.d.ts.map +1 -0
  153. package/dist/shims/crypto.d.ts +144 -0
  154. package/dist/shims/crypto.d.ts.map +1 -0
  155. package/dist/shims/dgram.d.ts +34 -0
  156. package/dist/shims/dgram.d.ts.map +1 -0
  157. package/dist/shims/dns.d.ts +91 -0
  158. package/dist/shims/dns.d.ts.map +1 -0
  159. package/dist/shims/domain.d.ts +25 -0
  160. package/dist/shims/domain.d.ts.map +1 -0
  161. package/dist/shims/esbuild.d.ts +205 -0
  162. package/dist/shims/esbuild.d.ts.map +1 -0
  163. package/dist/shims/fs.d.ts +25 -0
  164. package/dist/shims/fs.d.ts.map +1 -0
  165. package/dist/shims/http2.d.ts +81 -0
  166. package/dist/shims/http2.d.ts.map +1 -0
  167. package/dist/shims/inspector.d.ts +25 -0
  168. package/dist/shims/inspector.d.ts.map +1 -0
  169. package/dist/shims/module.d.ts +22 -0
  170. package/dist/shims/module.d.ts.map +1 -0
  171. package/dist/shims/os.d.ts +159 -0
  172. package/dist/shims/os.d.ts.map +1 -0
  173. package/dist/shims/path.d.ts +52 -0
  174. package/dist/shims/path.d.ts.map +1 -0
  175. package/dist/shims/perf_hooks.d.ts +50 -0
  176. package/dist/shims/perf_hooks.d.ts.map +1 -0
  177. package/dist/shims/process.d.ts +226 -0
  178. package/dist/shims/process.d.ts.map +1 -0
  179. package/dist/shims/rollup.d.ts +71 -0
  180. package/dist/shims/rollup.d.ts.map +1 -0
  181. package/dist/shims/string_decoder.d.ts +41 -0
  182. package/dist/shims/string_decoder.d.ts.map +1 -0
  183. package/dist/shims/sync-child.d.ts +64 -0
  184. package/dist/shims/sync-child.d.ts.map +1 -0
  185. package/dist/shims/tls.d.ts +53 -0
  186. package/dist/shims/tls.d.ts.map +1 -0
  187. package/dist/shims/url.d.ts +84 -0
  188. package/dist/shims/url.d.ts.map +1 -0
  189. package/dist/shims/v8.d.ts +73 -0
  190. package/dist/shims/v8.d.ts.map +1 -0
  191. package/dist/shims/vfs-adapter.d.ts +126 -0
  192. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  193. package/dist/shims/vm.d.ts +52 -0
  194. package/dist/shims/vm.d.ts.map +1 -0
  195. package/dist/shims/wasi.d.ts +78 -0
  196. package/dist/shims/wasi.d.ts.map +1 -0
  197. package/dist/shims/worker_threads.d.ts +66 -0
  198. package/dist/shims/worker_threads.d.ts.map +1 -0
  199. package/dist/shims/zlib-constants.d.ts +66 -0
  200. package/dist/shims/zlib-constants.d.ts.map +1 -0
  201. package/dist/shims/zlib.d.ts +102 -0
  202. package/dist/shims/zlib.d.ts.map +1 -0
  203. package/dist/transform.d.ts +24 -0
  204. package/dist/transform.d.ts.map +1 -0
  205. package/dist/types/package-json.d.ts +18 -0
  206. package/dist/types/package-json.d.ts.map +1 -0
  207. package/dist/utils/binary-encoding.d.ts +13 -0
  208. package/dist/utils/binary-encoding.d.ts.map +1 -0
  209. package/dist/utils/glob.d.ts +19 -0
  210. package/dist/utils/glob.d.ts.map +1 -0
  211. package/dist/utils/hash.d.ts +6 -0
  212. package/dist/utils/hash.d.ts.map +1 -0
  213. package/dist/virtual-fs.d.ts +259 -0
  214. package/dist/virtual-fs.d.ts.map +1 -0
  215. package/dist/vite-plugin.cjs +50 -0
  216. package/dist/vite-plugin.cjs.map +1 -0
  217. package/dist/vite-plugin.d.ts +36 -0
  218. package/dist/vite-plugin.d.ts.map +1 -0
  219. package/dist/vite-plugin.mjs +31 -0
  220. package/dist/vite-plugin.mjs.map +1 -0
  221. package/dist/worker/runtime-worker.d.ts +8 -0
  222. package/dist/worker/runtime-worker.d.ts.map +1 -0
  223. package/dist/worker-runtime.d.ts +50 -0
  224. package/dist/worker-runtime.d.ts.map +1 -0
  225. package/package.json +88 -0
  226. package/src/code-transforms.ts +560 -0
  227. package/src/config/cdn.ts +13 -0
  228. package/src/create-runtime.ts +89 -0
  229. package/src/host-globals.ts +121 -0
  230. package/src/index.ts +235 -0
  231. package/src/node-internals.ts +283 -0
  232. package/src/node-lib/LICENSE +47 -0
  233. package/src/node-lib/_http_agent.js +547 -0
  234. package/src/node-lib/_http_client.js +996 -0
  235. package/src/node-lib/_http_common.js +269 -0
  236. package/src/node-lib/_http_incoming.js +453 -0
  237. package/src/node-lib/_http_outgoing.js +1262 -0
  238. package/src/node-lib/_http_server.js +1230 -0
  239. package/src/node-lib/assert/strict.js +3 -0
  240. package/src/node-lib/assert.js +844 -0
  241. package/src/node-lib/binding/blob.ts +35 -0
  242. package/src/node-lib/binding/buffer.ts +465 -0
  243. package/src/node-lib/binding/cares_wrap.ts +57 -0
  244. package/src/node-lib/binding/fds.ts +80 -0
  245. package/src/node-lib/binding/fs.ts +857 -0
  246. package/src/node-lib/binding/handles.ts +187 -0
  247. package/src/node-lib/binding/http_parser.ts +536 -0
  248. package/src/node-lib/binding/index.ts +77 -0
  249. package/src/node-lib/binding/llhttp-wasm.ts +670 -0
  250. package/src/node-lib/binding/misc.ts +252 -0
  251. package/src/node-lib/binding/pipe_wrap.ts +166 -0
  252. package/src/node-lib/binding/process_wrap.ts +371 -0
  253. package/src/node-lib/binding/spawn_sync.ts +141 -0
  254. package/src/node-lib/binding/stream_wrap.ts +413 -0
  255. package/src/node-lib/binding/stubs.ts +19 -0
  256. package/src/node-lib/binding/tcp_wrap.ts +254 -0
  257. package/src/node-lib/binding/tty_wrap.ts +56 -0
  258. package/src/node-lib/binding/util.ts +274 -0
  259. package/src/node-lib/binding/uv.ts +102 -0
  260. package/src/node-lib/binding/zlib-pako.ts +50 -0
  261. package/src/node-lib/binding/zlib.ts +259 -0
  262. package/src/node-lib/buffer-module.ts +70 -0
  263. package/src/node-lib/buffer.js +1373 -0
  264. package/src/node-lib/child-process-module.ts +58 -0
  265. package/src/node-lib/child_process.js +1046 -0
  266. package/src/node-lib/constants.js +41 -0
  267. package/src/node-lib/diagnostics_channel.js +438 -0
  268. package/src/node-lib/events-module.ts +80 -0
  269. package/src/node-lib/events.js +1223 -0
  270. package/src/node-lib/fs-module.ts +43 -0
  271. package/src/node-lib/fs.js +3377 -0
  272. package/src/node-lib/http-bridge.ts +299 -0
  273. package/src/node-lib/http-module.ts +53 -0
  274. package/src/node-lib/http.js +198 -0
  275. package/src/node-lib/https.js +429 -0
  276. package/src/node-lib/internal/assert/assertion_error.js +417 -0
  277. package/src/node-lib/internal/assert/calltracker.js +153 -0
  278. package/src/node-lib/internal/assert/myers_diff.js +177 -0
  279. package/src/node-lib/internal/assert/utils.js +278 -0
  280. package/src/node-lib/internal/buffer.js +1120 -0
  281. package/src/node-lib/internal/child_process/serialization.js +169 -0
  282. package/src/node-lib/internal/child_process.js +1135 -0
  283. package/src/node-lib/internal/constants.js +56 -0
  284. package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
  285. package/src/node-lib/internal/errors.js +1912 -0
  286. package/src/node-lib/internal/events/abort_listener.js +54 -0
  287. package/src/node-lib/internal/events/symbols.js +11 -0
  288. package/src/node-lib/internal/fixed_queue.js +119 -0
  289. package/src/node-lib/internal/freelist.js +30 -0
  290. package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
  291. package/src/node-lib/internal/fs/cp/cp.js +382 -0
  292. package/src/node-lib/internal/fs/dir.js +369 -0
  293. package/src/node-lib/internal/fs/glob.js +763 -0
  294. package/src/node-lib/internal/fs/promises.js +1312 -0
  295. package/src/node-lib/internal/fs/read/context.js +129 -0
  296. package/src/node-lib/internal/fs/recursive_watch.js +275 -0
  297. package/src/node-lib/internal/fs/rimraf.js +311 -0
  298. package/src/node-lib/internal/fs/streams.js +571 -0
  299. package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
  300. package/src/node-lib/internal/fs/utils.js +987 -0
  301. package/src/node-lib/internal/fs/watchers.js +418 -0
  302. package/src/node-lib/internal/http.js +62 -0
  303. package/src/node-lib/internal/mime.js +389 -0
  304. package/src/node-lib/internal/modules/customization_hooks.js +406 -0
  305. package/src/node-lib/internal/net.js +95 -0
  306. package/src/node-lib/internal/querystring.js +119 -0
  307. package/src/node-lib/internal/readline/callbacks.js +132 -0
  308. package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
  309. package/src/node-lib/internal/readline/interface.js +1418 -0
  310. package/src/node-lib/internal/readline/promises.js +144 -0
  311. package/src/node-lib/internal/readline/utils.js +405 -0
  312. package/src/node-lib/internal/socket_list.js +108 -0
  313. package/src/node-lib/internal/stream_base_commons.js +280 -0
  314. package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
  315. package/src/node-lib/internal/streams/compose.js +257 -0
  316. package/src/node-lib/internal/streams/destroy.js +361 -0
  317. package/src/node-lib/internal/streams/duplex.js +203 -0
  318. package/src/node-lib/internal/streams/duplexify.js +379 -0
  319. package/src/node-lib/internal/streams/duplexpair.js +62 -0
  320. package/src/node-lib/internal/streams/end-of-stream.js +331 -0
  321. package/src/node-lib/internal/streams/from.js +208 -0
  322. package/src/node-lib/internal/streams/lazy_transform.js +57 -0
  323. package/src/node-lib/internal/streams/legacy.js +125 -0
  324. package/src/node-lib/internal/streams/operators.js +436 -0
  325. package/src/node-lib/internal/streams/passthrough.js +47 -0
  326. package/src/node-lib/internal/streams/pipeline.js +465 -0
  327. package/src/node-lib/internal/streams/readable.js +1762 -0
  328. package/src/node-lib/internal/streams/state.js +51 -0
  329. package/src/node-lib/internal/streams/transform.js +204 -0
  330. package/src/node-lib/internal/streams/utils.js +363 -0
  331. package/src/node-lib/internal/streams/writable.js +1163 -0
  332. package/src/node-lib/internal/tty.js +260 -0
  333. package/src/node-lib/internal/util/colors.js +40 -0
  334. package/src/node-lib/internal/util/comparisons.js +1028 -0
  335. package/src/node-lib/internal/util/debuglog.js +524 -0
  336. package/src/node-lib/internal/util/inspect.js +2535 -0
  337. package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
  338. package/src/node-lib/internal/util/parse_args/utils.js +197 -0
  339. package/src/node-lib/internal/util.js +1003 -0
  340. package/src/node-lib/internal/validators.js +654 -0
  341. package/src/node-lib/internals/addresses.ts +159 -0
  342. package/src/node-lib/internals/buffer-and-streams.ts +224 -0
  343. package/src/node-lib/internals/child-process.ts +64 -0
  344. package/src/node-lib/internals/events-util.ts +105 -0
  345. package/src/node-lib/internals/index.ts +66 -0
  346. package/src/node-lib/internals/modules.ts +117 -0
  347. package/src/node-lib/internals/readline-access.ts +16 -0
  348. package/src/node-lib/internals/runtime.ts +277 -0
  349. package/src/node-lib/internals/util.ts +98 -0
  350. package/src/node-lib/lazy.ts +158 -0
  351. package/src/node-lib/load.ts +390 -0
  352. package/src/node-lib/module-hooks.ts +281 -0
  353. package/src/node-lib/net-module.ts +248 -0
  354. package/src/node-lib/net.js +2540 -0
  355. package/src/node-lib/node-versions.ts +34 -0
  356. package/src/node-lib/os.js +356 -0
  357. package/src/node-lib/path.js +1694 -0
  358. package/src/node-lib/primordials.js +743 -0
  359. package/src/node-lib/public-modules.ts +109 -0
  360. package/src/node-lib/punycode.js +455 -0
  361. package/src/node-lib/querystring.js +484 -0
  362. package/src/node-lib/readline/promises.js +73 -0
  363. package/src/node-lib/readline.js +523 -0
  364. package/src/node-lib/require-hook.ts +27 -0
  365. package/src/node-lib/small-modules.ts +35 -0
  366. package/src/node-lib/sources.ts +200 -0
  367. package/src/node-lib/stream/promises.js +44 -0
  368. package/src/node-lib/stream-module.ts +101 -0
  369. package/src/node-lib/stream.js +152 -0
  370. package/src/node-lib/timers.ts +33 -0
  371. package/src/node-lib/tty.js +168 -0
  372. package/src/node-lib/util-module.ts +104 -0
  373. package/src/node-lib/util.js +689 -0
  374. package/src/node-lib/wasi.js +179 -0
  375. package/src/node-lib/zlib.js +1036 -0
  376. package/src/node-resolution.ts +241 -0
  377. package/src/node-resolver.ts +33 -0
  378. package/src/npm/index.ts +425 -0
  379. package/src/npm/registry.ts +235 -0
  380. package/src/npm/resolver.ts +589 -0
  381. package/src/npm/tarball.ts +246 -0
  382. package/src/process-tokens.ts +156 -0
  383. package/src/punycode-source.ts +6 -0
  384. package/src/runtime-interface.ts +85 -0
  385. package/src/runtime.ts +3073 -0
  386. package/src/server-bridge.ts +971 -0
  387. package/src/shims/async_hooks.ts +181 -0
  388. package/src/shims/child_process.ts +1591 -0
  389. package/src/shims/cluster.ts +79 -0
  390. package/src/shims/command-line.ts +79 -0
  391. package/src/shims/constants.ts +68 -0
  392. package/src/shims/crypto-constants.ts +11 -0
  393. package/src/shims/crypto.ts +1061 -0
  394. package/src/shims/dgram.ts +47 -0
  395. package/src/shims/dns.ts +185 -0
  396. package/src/shims/domain.ts +58 -0
  397. package/src/shims/esbuild.ts +1638 -0
  398. package/src/shims/fs.ts +82 -0
  399. package/src/shims/http2.ts +96 -0
  400. package/src/shims/inspector.ts +30 -0
  401. package/src/shims/module.ts +86 -0
  402. package/src/shims/os.ts +195 -0
  403. package/src/shims/path.ts +246 -0
  404. package/src/shims/perf_hooks.ts +92 -0
  405. package/src/shims/process.ts +804 -0
  406. package/src/shims/rollup.ts +149 -0
  407. package/src/shims/string_decoder.ts +396 -0
  408. package/src/shims/sync-child.ts +469 -0
  409. package/src/shims/tls.ts +94 -0
  410. package/src/shims/url.ts +217 -0
  411. package/src/shims/v8.ts +113 -0
  412. package/src/shims/vfs-adapter.ts +408 -0
  413. package/src/shims/vm.ts +132 -0
  414. package/src/shims/wasi.ts +1440 -0
  415. package/src/shims/worker_threads.ts +114 -0
  416. package/src/shims/zlib-constants.ts +65 -0
  417. package/src/shims/zlib.ts +228 -0
  418. package/src/transform.ts +324 -0
  419. package/src/types/external.d.ts +55 -0
  420. package/src/types/package-json.ts +17 -0
  421. package/src/types/pako-zlib.d.ts +30 -0
  422. package/src/types/sha.js.d.ts +14 -0
  423. package/src/utils/binary-encoding.ts +43 -0
  424. package/src/utils/glob.ts +54 -0
  425. package/src/utils/hash.ts +12 -0
  426. package/src/virtual-fs.ts +1048 -0
  427. package/src/vite-plugin.ts +76 -0
  428. package/src/worker/runtime-worker.ts +128 -0
  429. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,35 @@
1
+ /**
2
+ * `internalBinding('blob')`: the one call Node's `fs.openAsBlob` makes.
3
+ *
4
+ * Node's `internal/blob` reads the file through this binding and answers a
5
+ * Blob of the realm. The engine has no C++ blob handle, so the bytes come
6
+ * off the same tree the fs binding reads -- the run's filesystem, hung off
7
+ * the guest process under the same key -- and the Blob is the realm's own.
8
+ * This file does not import the fs binding: both are reached from the
9
+ * loader, and a cycle there left the open unanswered.
10
+ */
11
+ import type { VirtualFS } from '../../virtual-fs';
12
+
13
+ const kRunFilesystem = Symbol.for('tabnode.run.vfs');
14
+
15
+ function tree(): VirtualFS {
16
+ const realm = globalThis as unknown as { process?: Record<symbol, unknown> };
17
+ const found = realm.process?.[kRunFilesystem] as VirtualFS | undefined;
18
+ if (!found) {
19
+ throw Object.assign(new Error('fs: this realm has no filesystem; the engine gives a run one when it starts'), { code: 'ENOSYS' });
20
+ }
21
+ return found;
22
+ }
23
+
24
+ /**
25
+ * Node's `createBlobFromFilePath(path, { type })`: the bytes of that path
26
+ * as a realm `Blob`. `fs.openAsBlob` is a promise of this value.
27
+ */
28
+ export function createBlobFromFilePath(path: string, options?: { type?: string }): Blob {
29
+ const bytes = tree().readFileSync(path) as Uint8Array;
30
+ const copy = new Uint8Array(bytes.byteLength);
31
+ copy.set(bytes);
32
+ return new Blob([copy], { type: options?.type ?? '' });
33
+ }
34
+
35
+ export default { createBlobFromFilePath };
@@ -0,0 +1,465 @@
1
+ /**
2
+ * `internalBinding('buffer')`: the bytes under Node's own `buffer.js`.
3
+ *
4
+ * Node's `Buffer` is a `Uint8Array` subclass whose whole API -- `alloc`,
5
+ * `concat`, `toString`, `write`, `compare`, `indexOf`, `readInt32BE` and the
6
+ * rest -- is JavaScript in `lib/buffer.js` and `lib/internal/buffer.js`. What
7
+ * is native is only the part underneath: encode a string into bytes, decode
8
+ * bytes into a string, compare two ranges, find one range inside another,
9
+ * fill, copy, swap. That is this file, over `TextEncoder`, `TextDecoder` and
10
+ * the realm's own base64, and nothing above it.
11
+ *
12
+ * Every function here has the shape Node's own files call it with: the
13
+ * `*Slice` family is installed as a method and reads `this`; `base64Write`,
14
+ * `base64urlWrite`, `hexWrite` and `ucs2Write` likewise; `asciiWriteStatic`,
15
+ * `latin1WriteStatic` and `utf8WriteStatic` take the buffer as their first
16
+ * argument, which is how `internal/buffer.js` wraps them.
17
+ */
18
+
19
+ /** libuv has no say here: these are V8's, and the engine's realm is V8's. */
20
+ export const kMaxLength = 4294967296 - 1;
21
+ export const kStringMaxLength = 536870888;
22
+
23
+ /**
24
+ * Node's encoding numbers, from `enum encoding` in `node_buffer.h`. They are
25
+ * private to this binding and `internal/util`'s `encodingsMap`, which is the
26
+ * only thing that hands them over.
27
+ */
28
+ export const ASCII = 0;
29
+ export const UTF8 = 1;
30
+ export const BASE64 = 2;
31
+ export const UCS2 = 3;
32
+ export const LATIN1 = 4;
33
+ export const HEX = 5;
34
+ export const BUFFER = 6;
35
+ export const BASE64URL = 7;
36
+
37
+ const encoder = new TextEncoder();
38
+ /** A decoder per flavour: `fatal: false` is what Node's lossy decode is. */
39
+ const utf8Decoder = new TextDecoder('utf-8');
40
+ const latin1Decoder = new TextDecoder('latin1');
41
+ const ucs2Decoder = new TextDecoder('utf-16le');
42
+
43
+ const HEX_DIGITS = '0123456789abcdef';
44
+
45
+ function asBytes(value: Uint8Array): Uint8Array {
46
+ return value;
47
+ }
48
+
49
+ /** libuv's `uv_buf` clamp: a range inside the buffer, in order. */
50
+ function clamp(buffer: Uint8Array, start: number, end: number): [number, number] {
51
+ const length = buffer.length;
52
+ let from = start === undefined || Number.isNaN(start) ? 0 : Math.trunc(start);
53
+ let to = end === undefined || Number.isNaN(end) ? length : Math.trunc(end);
54
+ if (from < 0) from = 0;
55
+ if (to > length) to = length;
56
+ if (to < from) to = from;
57
+ return [from, to];
58
+ }
59
+
60
+ // ── Encoding a string into a buffer ────────────────────────────────────────
61
+
62
+ /** Node's `StringWrite<UTF8>`: as many whole code points as fit. */
63
+ export function utf8WriteStatic(buf: Uint8Array, string: string, offset = 0, length = buf.byteLength - offset): number {
64
+ const room = Math.min(length, buf.byteLength - offset);
65
+ if (room <= 0) return 0;
66
+ const { written } = encoder.encodeInto(string, buf.subarray(offset, offset + room));
67
+ return written ?? 0;
68
+ }
69
+
70
+ /** Node's `StringWrite<ASCII>`: the low seven bits of each unit, one byte each. */
71
+ export function asciiWriteStatic(buf: Uint8Array, string: string, offset = 0, length = buf.byteLength - offset): number {
72
+ const room = Math.min(length, buf.byteLength - offset, string.length);
73
+ for (let index = 0; index < room; index += 1) buf[offset + index] = string.charCodeAt(index) & 0x7f;
74
+ return room < 0 ? 0 : room;
75
+ }
76
+
77
+ /** Node's `StringWrite<LATIN1>`: the low eight bits of each unit. */
78
+ export function latin1WriteStatic(buf: Uint8Array, string: string, offset = 0, length = buf.byteLength - offset): number {
79
+ const room = Math.min(length, buf.byteLength - offset, string.length);
80
+ for (let index = 0; index < room; index += 1) buf[offset + index] = string.charCodeAt(index) & 0xff;
81
+ return room < 0 ? 0 : room;
82
+ }
83
+
84
+ /** Node's `StringWrite<UCS2>`: whole 16-bit units, little-endian. */
85
+ export function ucs2Write(this: Uint8Array, string: string, offset = 0, length = this.byteLength - offset): number {
86
+ const room = Math.min(length, this.byteLength - offset);
87
+ const units = Math.min(string.length, Math.floor(room / 2));
88
+ for (let index = 0; index < units; index += 1) {
89
+ const code = string.charCodeAt(index);
90
+ this[offset + index * 2] = code & 0xff;
91
+ this[offset + index * 2 + 1] = code >>> 8;
92
+ }
93
+ return units * 2;
94
+ }
95
+
96
+ /** Node's `StringWrite<HEX>`: whole byte pairs, stopping at the first that is not one. */
97
+ export function hexWrite(this: Uint8Array, string: string, offset = 0, length = this.byteLength - offset): number {
98
+ const room = Math.min(length, this.byteLength - offset);
99
+ const pairs = Math.min(Math.floor(string.length / 2), room);
100
+ let written = 0;
101
+ for (let index = 0; index < pairs; index += 1) {
102
+ const high = hexValue(string.charCodeAt(index * 2));
103
+ const low = hexValue(string.charCodeAt(index * 2 + 1));
104
+ if (high < 0 || low < 0) break;
105
+ this[offset + index] = (high << 4) | low;
106
+ written += 1;
107
+ }
108
+ return written;
109
+ }
110
+
111
+ function hexValue(code: number): number {
112
+ if (code >= 48 && code <= 57) return code - 48;
113
+ if (code >= 97 && code <= 102) return code - 87;
114
+ if (code >= 65 && code <= 70) return code - 55;
115
+ return -1;
116
+ }
117
+
118
+ const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
119
+
120
+ /**
121
+ * The bytes a base64 string stands for. Node reads either alphabet under
122
+ * either name -- `Buffer.from('+/', 'base64')` and
123
+ * `Buffer.from('-_', 'base64url')` are the same two bytes -- stops at the
124
+ * first `=`, and ignores anything that is a digit of neither.
125
+ */
126
+ function base64Bytes(string: string): Uint8Array {
127
+ let cleaned = '';
128
+ for (let index = 0; index < string.length; index += 1) {
129
+ const ch = string[index] as string;
130
+ if (ch === '=') break;
131
+ if (ch === '-') { cleaned += '+'; continue; }
132
+ if (ch === '_') { cleaned += '/'; continue; }
133
+ if (BASE64_ALPHABET.indexOf(ch) >= 0) cleaned += ch;
134
+ }
135
+ // A group of one digit stands for no byte at all and is dropped, as Node
136
+ // drops it; every other tail contributes what its bits carry.
137
+ const usable = cleaned.length - (cleaned.length % 4 === 1 ? 1 : 0);
138
+ const bytes: number[] = [];
139
+ let bits = 0;
140
+ let held = 0;
141
+ for (let index = 0; index < usable; index += 1) {
142
+ const value = BASE64_ALPHABET.indexOf(cleaned[index] as string);
143
+ held = (held << 6) | value;
144
+ bits += 6;
145
+ if (bits >= 8) { bits -= 8; bytes.push((held >> bits) & 0xff); }
146
+ }
147
+ return new Uint8Array(bytes);
148
+ }
149
+
150
+ /** Node's `StringWrite<BASE64>`. */
151
+ export function base64Write(this: Uint8Array, string: string, offset = 0, length = this.byteLength - offset): number {
152
+ const bytes = base64Bytes(string);
153
+ const room = Math.min(length, this.byteLength - offset, bytes.length);
154
+ if (room <= 0) return 0;
155
+ this.set(bytes.subarray(0, room), offset);
156
+ return room;
157
+ }
158
+
159
+ /** Node's `StringWrite<BASE64URL>`. */
160
+ export function base64urlWrite(this: Uint8Array, string: string, offset = 0, length = this.byteLength - offset): number {
161
+ const bytes = base64Bytes(string);
162
+ const room = Math.min(length, this.byteLength - offset, bytes.length);
163
+ if (room <= 0) return 0;
164
+ this.set(bytes.subarray(0, room), offset);
165
+ return room;
166
+ }
167
+
168
+ // ── Decoding a buffer into a string ────────────────────────────────────────
169
+
170
+ export function utf8Slice(this: Uint8Array, start?: number, end?: number): string {
171
+ const [from, to] = clamp(this, start as number, end as number);
172
+ return utf8Decoder.decode(this.subarray(from, to));
173
+ }
174
+
175
+ export function asciiSlice(this: Uint8Array, start?: number, end?: number): string {
176
+ const [from, to] = clamp(this, start as number, end as number);
177
+ let out = '';
178
+ for (let index = from; index < to; index += 1) out += String.fromCharCode((this[index] as number) & 0x7f);
179
+ return out;
180
+ }
181
+
182
+ export function latin1Slice(this: Uint8Array, start?: number, end?: number): string {
183
+ const [from, to] = clamp(this, start as number, end as number);
184
+ return latin1Decoder.decode(this.subarray(from, to));
185
+ }
186
+
187
+ export function ucs2Slice(this: Uint8Array, start?: number, end?: number): string {
188
+ const [from, to] = clamp(this, start as number, end as number);
189
+ // A trailing odd byte is dropped, as Node drops it.
190
+ const whole = to - ((to - from) % 2);
191
+ const bytes = this.subarray(from, whole);
192
+ // A view whose offset is odd cannot be a `Uint16Array`; copy that one.
193
+ const aligned = (bytes.byteOffset % 2) === 0 ? bytes : new Uint8Array(bytes);
194
+ return ucs2Decoder.decode(aligned);
195
+ }
196
+
197
+ export function hexSlice(this: Uint8Array, start?: number, end?: number): string {
198
+ const [from, to] = clamp(this, start as number, end as number);
199
+ let out = '';
200
+ for (let index = from; index < to; index += 1) {
201
+ const byte = this[index] as number;
202
+ out += HEX_DIGITS[byte >>> 4] as string;
203
+ out += HEX_DIGITS[byte & 0x0f] as string;
204
+ }
205
+ return out;
206
+ }
207
+
208
+ function base64Text(bytes: Uint8Array, url: boolean): string {
209
+ const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
210
+ let out = '';
211
+ for (let index = 0; index < bytes.length; index += 3) {
212
+ const a = bytes[index] as number;
213
+ const b = index + 1 < bytes.length ? bytes[index + 1] as number : -1;
214
+ const c = index + 2 < bytes.length ? bytes[index + 2] as number : -1;
215
+ out += alphabet[a >>> 2] as string;
216
+ out += alphabet[((a & 0x03) << 4) | (b < 0 ? 0 : b >>> 4)] as string;
217
+ out += b < 0 ? '=' : alphabet[((b & 0x0f) << 2) | (c < 0 ? 0 : c >>> 6)] as string;
218
+ out += c < 0 ? '=' : alphabet[c & 0x3f] as string;
219
+ }
220
+ if (!url) return out;
221
+ return out.replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '');
222
+ }
223
+
224
+ export function base64Slice(this: Uint8Array, start?: number, end?: number): string {
225
+ const [from, to] = clamp(this, start as number, end as number);
226
+ return base64Text(this.subarray(from, to), false);
227
+ }
228
+
229
+ export function base64urlSlice(this: Uint8Array, start?: number, end?: number): string {
230
+ const [from, to] = clamp(this, start as number, end as number);
231
+ return base64Text(this.subarray(from, to), true);
232
+ }
233
+
234
+ // ── The rest of what `buffer.js` asks for ──────────────────────────────────
235
+
236
+ /** Node's `ByteLengthUtf8`. */
237
+ export function byteLengthUtf8(string: string): number {
238
+ return encoder.encode(string).length;
239
+ }
240
+
241
+ /** Node's `Compare`: two buffers whole, as `memcmp` orders them. */
242
+ export function compare(a: Uint8Array, b: Uint8Array): number {
243
+ return compareRanges(asBytes(a), 0, a.length, asBytes(b), 0, b.length);
244
+ }
245
+
246
+ /** Node's `CompareOffset`: a range of one against a range of the other. */
247
+ export function compareOffset(
248
+ source: Uint8Array, target: Uint8Array,
249
+ targetStart = 0, sourceStart = 0, targetEnd = target.length, sourceEnd = source.length,
250
+ ): number {
251
+ return compareRanges(source, sourceStart, sourceEnd, target, targetStart, targetEnd);
252
+ }
253
+
254
+ function compareRanges(
255
+ a: Uint8Array, aStart: number, aEnd: number,
256
+ b: Uint8Array, bStart: number, bEnd: number,
257
+ ): number {
258
+ const aLength = aEnd - aStart;
259
+ const bLength = bEnd - bStart;
260
+ const shared = Math.min(aLength, bLength);
261
+ for (let index = 0; index < shared; index += 1) {
262
+ const left = a[aStart + index] as number;
263
+ const right = b[bStart + index] as number;
264
+ if (left !== right) return left < right ? -1 : 1;
265
+ }
266
+ if (aLength === bLength) return 0;
267
+ return aLength < bLength ? -1 : 1;
268
+ }
269
+
270
+ /**
271
+ * Node's `Copy(source, target, targetStart, sourceStart, toCopy)`. The last
272
+ * argument is a LENGTH, not an end offset: `buffer.js`'s `_copyActual` has
273
+ * already clamped the range and hands over how many bytes to move.
274
+ */
275
+ export function copy(source: Uint8Array, target: Uint8Array, targetStart = 0, sourceStart = 0, toCopy = source.length - sourceStart): number {
276
+ const room = Math.min(toCopy, source.length - sourceStart, target.length - targetStart);
277
+ if (room <= 0) return 0;
278
+ target.set(source.subarray(sourceStart, sourceStart + room), targetStart);
279
+ return room;
280
+ }
281
+
282
+ /**
283
+ * Node's `Fill` for a value that is not a number: a string in some encoding,
284
+ * or another buffer, repeated over the range. -1 says the value stands for no
285
+ * bytes at all, which is what `buffer.js` turns into ERR_INVALID_ARG_VALUE.
286
+ */
287
+ export function fill(buf: Uint8Array, value: unknown, start: number, end: number, encoding?: string): number {
288
+ const [from, to] = clamp(buf, start, end);
289
+ if (to <= from) return 0;
290
+ let pattern: Uint8Array;
291
+ if (typeof value === 'string') {
292
+ pattern = bytesOfString(value, encoding ?? 'utf8');
293
+ } else if (value instanceof Uint8Array) {
294
+ pattern = value;
295
+ } else {
296
+ return -1;
297
+ }
298
+ if (pattern.length === 0) return -1;
299
+ for (let index = from; index < to; index += 1) {
300
+ buf[index] = pattern[(index - from) % pattern.length] as number;
301
+ }
302
+ return to - from;
303
+ }
304
+
305
+ /** The bytes a string stands for in one of Node's encodings. */
306
+ export function bytesOfString(value: string, encoding: string): Uint8Array {
307
+ switch (encoding) {
308
+ case 'ascii': { const out = new Uint8Array(value.length); asciiWriteStatic(out, value, 0, out.length); return out; }
309
+ case 'latin1': case 'binary': { const out = new Uint8Array(value.length); latin1WriteStatic(out, value, 0, out.length); return out; }
310
+ case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': {
311
+ const out = new Uint8Array(value.length * 2);
312
+ ucs2Write.call(out, value, 0, out.length);
313
+ return out;
314
+ }
315
+ case 'hex': { const out = new Uint8Array(Math.floor(value.length / 2)); const written = hexWrite.call(out, value, 0, out.length); return out.subarray(0, written); }
316
+ case 'base64': case 'base64url': return base64Bytes(value);
317
+ default: return encoder.encode(value);
318
+ }
319
+ }
320
+
321
+ /** Node's `IndexOfNumber`. */
322
+ export function indexOfNumber(buffer: Uint8Array, value: number, byteOffset: number, isForward: boolean): number {
323
+ const byte = value & 0xff;
324
+ if (isForward) {
325
+ let from = byteOffset < 0 ? buffer.length + byteOffset : byteOffset;
326
+ if (from < 0) from = 0;
327
+ for (let index = from; index < buffer.length; index += 1) if (buffer[index] === byte) return index;
328
+ return -1;
329
+ }
330
+ let from = byteOffset < 0 ? buffer.length + byteOffset : Math.min(byteOffset, buffer.length - 1);
331
+ if (from >= buffer.length) from = buffer.length - 1;
332
+ for (let index = from; index >= 0; index -= 1) if (buffer[index] === byte) return index;
333
+ return -1;
334
+ }
335
+
336
+ /** Node's `IndexOfBuffer`. */
337
+ export function indexOfBuffer(buffer: Uint8Array, value: Uint8Array, byteOffset: number, encoding: number, isForward: boolean): number {
338
+ // A 16-bit encoding searches on even boundaries only, as Node's does.
339
+ const step = encoding === UCS2 ? 2 : 1;
340
+ return searchBytes(buffer, value, byteOffset, isForward, step);
341
+ }
342
+
343
+ /** Node's `IndexOfString`. */
344
+ export function indexOfString(buffer: Uint8Array, value: string, byteOffset: number, encoding: number, isForward: boolean): number {
345
+ const name = encoding === UCS2 ? 'utf16le' : encoding === LATIN1 ? 'latin1' : encoding === ASCII ? 'ascii'
346
+ : encoding === HEX ? 'hex' : encoding === BASE64 ? 'base64' : encoding === BASE64URL ? 'base64url' : 'utf8';
347
+ return indexOfBuffer(buffer, bytesOfString(value, name), byteOffset, encoding, isForward);
348
+ }
349
+
350
+ function searchBytes(buffer: Uint8Array, needle: Uint8Array, byteOffset: number, isForward: boolean, step: number): number {
351
+ const length = buffer.length;
352
+ if (needle.length === 0) {
353
+ if (isForward) return byteOffset > length ? length : (byteOffset < 0 ? Math.max(0, length + byteOffset) : byteOffset);
354
+ return byteOffset > length ? length : (byteOffset < 0 ? Math.max(0, length + byteOffset) : byteOffset);
355
+ }
356
+ if (needle.length > length) return -1;
357
+ const matches = (at: number): boolean => {
358
+ for (let index = 0; index < needle.length; index += 1) if (buffer[at + index] !== needle[index]) return false;
359
+ return true;
360
+ };
361
+ if (isForward) {
362
+ let from = byteOffset < 0 ? length + byteOffset : byteOffset;
363
+ if (from < 0) from = 0;
364
+ if (step === 2 && (from % 2) !== 0) from += 1;
365
+ for (let index = from; index + needle.length <= length; index += step) if (matches(index)) return index;
366
+ return -1;
367
+ }
368
+ let from = byteOffset < 0 ? length + byteOffset : byteOffset;
369
+ if (from > length - needle.length) from = length - needle.length;
370
+ if (from < 0) return -1;
371
+ if (step === 2 && (from % 2) !== 0) from -= 1;
372
+ for (let index = from; index >= 0; index -= step) if (matches(index)) return index;
373
+ return -1;
374
+ }
375
+
376
+ /** Node's `Swap16`/`Swap32`/`Swap64`, in place, answering the same buffer. */
377
+ export function swap16(buf: Uint8Array): Uint8Array {
378
+ for (let index = 0; index < buf.length; index += 2) {
379
+ const a = buf[index] as number;
380
+ buf[index] = buf[index + 1] as number;
381
+ buf[index + 1] = a;
382
+ }
383
+ return buf;
384
+ }
385
+ export function swap32(buf: Uint8Array): Uint8Array {
386
+ for (let index = 0; index < buf.length; index += 4) {
387
+ for (let at = 0; at < 2; at += 1) {
388
+ const a = buf[index + at] as number;
389
+ buf[index + at] = buf[index + 3 - at] as number;
390
+ buf[index + 3 - at] = a;
391
+ }
392
+ }
393
+ return buf;
394
+ }
395
+ export function swap64(buf: Uint8Array): Uint8Array {
396
+ for (let index = 0; index < buf.length; index += 8) {
397
+ for (let at = 0; at < 4; at += 1) {
398
+ const a = buf[index + at] as number;
399
+ buf[index + at] = buf[index + 7 - at] as number;
400
+ buf[index + 7 - at] = a;
401
+ }
402
+ }
403
+ return buf;
404
+ }
405
+
406
+ /** Node's `IsUtf8`: whether the bytes decode without a replacement. */
407
+ export function isUtf8(buf: Uint8Array): boolean {
408
+ try { new TextDecoder('utf-8', { fatal: true }).decode(buf); return true; } catch { return false; }
409
+ }
410
+
411
+ /** Node's `IsAscii`: every byte under 128. */
412
+ export function isAscii(buf: Uint8Array): boolean {
413
+ for (let index = 0; index < buf.length; index += 1) if ((buf[index] as number) > 0x7f) return false;
414
+ return true;
415
+ }
416
+
417
+ /** Node's `Atob`: the string a base64 one stands for, -1 for one that is not. */
418
+ export function atob(input: string): string | number {
419
+ try { return globalThis.atob(input); } catch { return -1; }
420
+ }
421
+
422
+ /** Node's `Btoa`: the base64 of a latin1 string, -1 for a character outside it. */
423
+ export function btoa(input: string): string | number {
424
+ try { return globalThis.btoa(input); } catch { return -1; }
425
+ }
426
+
427
+ /**
428
+ * Node's zero-fill toggle: `Buffer.allocUnsafe` reads it to decide whether the
429
+ * memory it takes is cleared. A realm's `new Uint8Array(n)` is always zeroed
430
+ * and there is no uncleared memory to hand out, so the toggle stays 0 and
431
+ * "unsafe" costs nothing and hides nothing.
432
+ */
433
+ const zeroFillToggle = new Uint32Array(1);
434
+ export function getZeroFillToggle(): Uint32Array {
435
+ return zeroFillToggle;
436
+ }
437
+
438
+ /**
439
+ * Node's `DetachArrayBuffer` and `CopyArrayBuffer`, which `Blob` and the
440
+ * worker's message port use. A realm can detach through `structuredClone`'s
441
+ * transfer list, and that is the only detach there is here.
442
+ */
443
+ export function detachArrayBuffer(buffer: ArrayBuffer): void {
444
+ try { structuredClone(buffer, { transfer: [buffer] }); } catch { /* a realm that refuses leaves it attached */ }
445
+ }
446
+ export function copyArrayBuffer(dest: ArrayBuffer, destOffset: number, source: ArrayBuffer, sourceOffset: number, length: number): void {
447
+ new Uint8Array(dest).set(new Uint8Array(source, sourceOffset, length), destOffset);
448
+ }
449
+
450
+ /** Node's `SetBufferPrototype`: C++ keeps it to build buffers; nothing here does. */
451
+ export function setBufferPrototype(_proto: object): void {}
452
+
453
+ /** Node's `CreateFromString`: `buffer.js` has its own and never calls this. */
454
+ export function createFromString(string: string, encoding: number): Uint8Array {
455
+ return bytesOfString(string, encoding === UCS2 ? 'utf16le' : encoding === LATIN1 ? 'latin1' : 'utf8');
456
+ }
457
+
458
+ export default {
459
+ byteLengthUtf8, compare, compareOffset, copy, fill,
460
+ isAscii, isUtf8, indexOfBuffer, indexOfNumber, indexOfString,
461
+ swap16, swap32, swap64, kMaxLength, kStringMaxLength, atob, btoa,
462
+ asciiSlice, base64Slice, base64urlSlice, latin1Slice, hexSlice, ucs2Slice, utf8Slice,
463
+ asciiWriteStatic, base64Write, base64urlWrite, latin1WriteStatic, hexWrite, ucs2Write, utf8WriteStatic,
464
+ getZeroFillToggle, detachArrayBuffer, copyArrayBuffer, setBufferPrototype, createFromString,
465
+ };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `internalBinding('cares_wrap')`: the address arithmetic Node's `net` needs.
3
+ *
4
+ * Node's own `internal/net.js` recognises an IP with its own regular
5
+ * expressions and does not ask this binding; `net.js` asks it for one thing
6
+ * only, `convertIpv6StringToBuffer`, which it reads the first two bytes of to
7
+ * tell a link-local address from a routable one. Lookups stay the engine's
8
+ * `dns`, which answers for this host and nothing else.
9
+ */
10
+ import { libRequire } from '../require-hook';
11
+
12
+ /** Node's own `isIP` family, from the vendored `internal/net.js`. */
13
+ function internalNet(): { isIP(s: string): number; isIPv4(s: string): boolean; isIPv6(s: string): boolean } {
14
+ return libRequire('internal/net') as { isIP(s: string): number; isIPv4(s: string): boolean; isIPv6(s: string): boolean };
15
+ }
16
+
17
+ /**
18
+ * An IPv6 address as its sixteen bytes. `::` fills the gap, and a trailing
19
+ * IPv4 form (`::ffff:127.0.0.1`) is its four bytes at the end, as inet_pton
20
+ * reads one.
21
+ */
22
+ export function convertIpv6StringToBuffer(address: string): Uint8Array {
23
+ const bytes = new Uint8Array(16);
24
+ let text = address.split('%')[0];
25
+ if (text.startsWith('[') && text.endsWith(']')) text = text.slice(1, -1);
26
+ const tail: number[] = [];
27
+ const dotted = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(text);
28
+ if (dotted) {
29
+ for (const part of dotted[1].split('.')) tail.push(Number(part) & 255);
30
+ text = text.slice(0, dotted.index);
31
+ if (text.endsWith(':') && !text.endsWith('::')) text = text.slice(0, -1);
32
+ }
33
+ const [head, rest] = text.split('::');
34
+ const readGroups = (piece: string): number[] => {
35
+ const out: number[] = [];
36
+ for (const group of piece.split(':')) {
37
+ if (group === '') continue;
38
+ const value = Number.parseInt(group, 16);
39
+ out.push((value >> 8) & 255, value & 255);
40
+ }
41
+ return out;
42
+ };
43
+ const left = readGroups(head ?? '');
44
+ const right = rest === undefined ? [] : readGroups(rest);
45
+ const all = rest === undefined
46
+ ? [...left, ...tail]
47
+ : [...left, ...new Array(16 - left.length - right.length - tail.length).fill(0), ...right, ...tail];
48
+ bytes.set(all.slice(0, 16));
49
+ return bytes;
50
+ }
51
+
52
+ export default {
53
+ get isIP() { return internalNet().isIP; },
54
+ get isIPv4() { return internalNet().isIPv4; },
55
+ get isIPv6() { return internalNet().isIPv6; },
56
+ convertIpv6StringToBuffer,
57
+ };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The file descriptors a handle can be opened on.
3
+ *
4
+ * libuv answers `uv_guess_handle(fd)` from the kernel. The engine has no
5
+ * kernel and no descriptors of its own beyond the three a process is started
6
+ * with and the ones a spawn hands a child, so the table is what the engine
7
+ * itself opened: a `Pipe` or `TCP` registered here by the run that made it,
8
+ * and the three standard ones, which are pipes because the engine's stdio is
9
+ * a stream the host reads, never a terminal it owns.
10
+ *
11
+ * `net.js` reads it through `internal/util`'s `guessHandleType` when a program
12
+ * builds a socket on a descriptor (`new net.Socket({ fd })`) and when a server
13
+ * listens on one.
14
+ */
15
+
16
+ import type { ProcessToken } from '../../process-tokens';
17
+ import { currentOwner } from './handles';
18
+
19
+ /** What libuv answers for a descriptor. */
20
+ export type HandleType = 'TCP' | 'TTY' | 'UDP' | 'FILE' | 'PIPE' | 'UNKNOWN';
21
+
22
+ /** The descriptors the engine itself opened, and the handle each names. */
23
+ const openFds = new Map<number, { type: HandleType; handle: unknown }>();
24
+
25
+ /**
26
+ * The descriptors one run was STARTED with, which are that run's alone.
27
+ *
28
+ * A child's IPC channel is fd 3 in every child, because Node writes
29
+ * `NODE_CHANNEL_FD=3` into its environment and the child opens the number it
30
+ * is told. Two forked children in one realm would then both open the same
31
+ * number, so the number is read against the run that asks: the parent's
32
+ * `spawn` records the child's end of the channel under the child's name, and
33
+ * the child's `new Pipe(IPC).open(3)` finds its own.
34
+ */
35
+ const runFds = new Map<ProcessToken, Map<number, { type: HandleType; handle: unknown }>>();
36
+
37
+ let nextFd = 20;
38
+
39
+ /** Record a descriptor a run is started with, under that run's name. */
40
+ export function registerRunFd(token: ProcessToken, fd: number, type: HandleType, handle: unknown): void {
41
+ let table = runFds.get(token);
42
+ if (!table) { table = new Map(); runFds.set(token, table); }
43
+ table.set(fd, { type, handle });
44
+ }
45
+
46
+ /** A run that has ended was started with nothing. */
47
+ export function releaseRunFds(token: ProcessToken): void {
48
+ runFds.delete(token);
49
+ }
50
+
51
+ /** The descriptor table of the run asking, where the asking run has one. */
52
+ function tableOfAskingRun(): Map<number, { type: HandleType; handle: unknown }> | undefined {
53
+ const token = currentOwner();
54
+ return token === null ? undefined : runFds.get(token);
55
+ }
56
+
57
+ /** Record a handle under a descriptor of the engine's own, and answer the number. */
58
+ export function registerFd(type: HandleType, handle: unknown): number {
59
+ const fd = nextFd++;
60
+ openFds.set(fd, { type, handle });
61
+ return fd;
62
+ }
63
+
64
+ /** The handle a descriptor names, for `Pipe.open(fd)` and `TCP.open(fd)`. */
65
+ export function handleForFd(fd: number): unknown {
66
+ return tableOfAskingRun()?.get(fd)?.handle ?? openFds.get(fd)?.handle;
67
+ }
68
+
69
+ /** Give a descriptor back; a handle that closes stops answering for one. */
70
+ export function releaseFd(fd: number): void {
71
+ openFds.delete(fd);
72
+ }
73
+
74
+ /** libuv's `uv_guess_handle`. */
75
+ export function guessHandleTypeOfFd(fd: number): HandleType {
76
+ const open = tableOfAskingRun()?.get(fd) ?? openFds.get(fd);
77
+ if (open) return open.type;
78
+ if (fd === 0 || fd === 1 || fd === 2) return 'PIPE';
79
+ return 'FILE';
80
+ }